私はいくつかのレコードを持っています。SQLの各部分の半分が更新されます
私は操作を行うことができるように一時テーブルに入れました。具体的には、私は何か他のものに残りの半分を変更、その後、何かの列に個別の値の半分を変更する必要があります。
私の一時テーブルでは、私は
Animals | SeveralOtherColumns
dog
cat
fish
dog
dog
dog
fish
cat
cat
cat
を持っていると私は持っている必要があり
Animals | SeveralOtherColumns
dog_A
cat_A
fish_A
dog_A
dog_B
dog_B
fish_B
cat_A
cat_B
cat_B
具体的な値がAnimals
になるかどうか、または個別の値がいくつあるかはわかりません。
だから私の最初の考えは次のとおりです。
SET @count = (SELECT COUNT(DISTINCT(Animals)) FROM #temptable)
--this throws an error, doesn't like the assignment
SET @animals = (SELECT DISTINCT(Animals) FROM #temptable)
WHILE (@count > 0)
BEGIN
-- about here is where I'm lost
-- update the first half of the distinct value
UPDATE #temptable SET #temptable.Animals = #temptable.Animals + '_A'
WHERE Animals = @animals[@count] --Pretty sure this won't work but gets the point across
FROM (SELECT TOP 50 PERCENT FROM #temptable)
-- update the remaining set of that distinct value
UPDATE #temptable SET #temptable.Animals = #temptable.Animals + '_B'
WHERE Animals = @animals[@count]
FROM #temptable
SET @count = @count - 1
END
サフィックスの背後にある論理は何ですか?それを取得しないでください – Lamak
あなたは任意のSQLサーバーの互換性が必要ですか、または最新のバージョンはあなたの目標ですか? – infiniteRefactor
@Lamakそれぞれ異なる値の前半には_Aが追加され、残りには_Bが追加されます。人間の言語で説明するために変わった種類... –