2010-12-08 26 views
0

我有一个表中有7个数量列表示客户每周的每一天的订单...这是通过设计,无法更改。是否有可能进行更新这样在一个更新语句中更新基于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”并执行特定的更新语句。我只是想知道是否有可能将所有这些都包含在存储过程中的一个更新语句中。

+0

是不是相同的UPDATE语句,只是使用不同的列? – guildsbounty 2010-12-08 19:43:44

回答

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'