我在表格中有7个数量列,表示客户每周一天的订单......这是设计使然无法更改的。是否可以执行这样的更新
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”并执行特定的更新语句。我只是想知道是否可以将所有这些包装在存储过程中的一个更新语句中。
答案 0 :(得分: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'