2010-12-08 9 views
0

顧客の各曜日の注文を表す表に7つの数量の列があります。これは仕様であり、変更できません。このような更新を行うことは可能ですか1つの更新ステートメントのcritereaに基づいて異なる列を更新します

update customerOrder 

case weekday(someDate) when 'SUN' then set Quantity1 = 1 end, 
case weekday(someDate) when 'MON' then set Quantity2 = 1 end, 
case weekday(someDate) when 'TUE' then set Quantity3 = 1 end, 
case weekday(someDate) when 'WED' then set Quantity4 = 1 end, 
case weekday(someDate) when 'THU' then set Quantity5 = 1 end, 
case weekday(someDate) when 'FRI' then set Quantity6 = 1 end, 
case weekday(someDate) when 'SAT' then set Quantity7 = 1 end 

WHERE accountNumber = 'ABC123' 

現在、私は "someDate"をチェックして特定の更新ステートメントを実行しています。私は、ストアドプロシージャ内の1つの更新ステートメントでこれをすべてラップすることが可能かどうかを疑問視していました。

+0

異なる列を使用するのと同じUPDATE文ですか? – guildsbounty

答えて

1
UPDATE 
    customerOrder 
SET 
    Quantity1 = CASE WEEKDAY(someDate) WHEN 'SUN' THEN 1 ELSE Quantity1 END, 
    Quantity2 = CASE WEEKDAY(someDate) WHEN 'MON' THEN 1 ELSE Quantity2 END, 
    Quantity3 = CASE WEEKDAY(someDate) WHEN 'TUE' THEN 1 ELSE Quantity3 END, 
    Quantity4 = CASE WEEKDAY(someDate) WHEN 'WED' THEN 1 ELSE Quantity4 END, 
    Quantity5 = CASE WEEKDAY(someDate) WHEN 'THU' THEN 1 ELSE Quantity5 END, 
    Quantity6 = CASE WEEKDAY(someDate) WHEN 'FRI' THEN 1 ELSE Quantity6 END, 
    Quantity7 = CASE WEEKDAY(someDate) WHEN 'SAT' THEN 1 ELSE Quantity7 END 
WHERE 
    accountNumber = 'ABC123' 
関連する問題