开发者

Multiple SET expressions in query?

开发者 https://www.devze.com 2023-01-24 01:30 出处:网络
Want to update specific data in a Table Column. I can use the below for one entry: UPDATE [BULDING].[dbo].[TB_DATA]

Want to update specific data in a Table Column.

I can use the below for one entry:

UPDATE [BULDING].[dbo].[TB_DATA]

SET OFFICE_ID = '4' where OFFICE__ID = '8';

But what should I use for multiple entry change - below obviously does not 开发者_Go百科work:

UPDATE [BULDING].[dbo].[TB_DATA]

SET OFFICE_ID = '4' where OFFICE_ID = '8'

SET OFFICE_ID = '4' where OFFICE_ID = '10'

SET OFFICE_ID = '11' where OFFICE__ID = '3';

Thanks!


UPDATE [BULDING].[dbo].[TB_DATA]
SET OFFICE_ID = 
    case when office_id in ('8', '10') then '4'
        when office_id = '3' then '11'
        else office_id
    end
0

精彩评论

暂无评论...
验证码 换一张
取 消