Alex
Alex

Reputation: 1733

Multiple SET expressions in query?

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 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!

Upvotes: 1

Views: 126

Answers (1)

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171391

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

Upvotes: 6

Related Questions