Tuesday, March 20, 2012

Revert Question

how do we change the value of specific column?(not updating).

for example the value of ID 01 - 03 is 1 and ID 04 and 05 is 0. how do we revert it?

in one statement only

Table1

ID Value

01 1

02 1

03 1

04 0

05 0

One of many solutions that's possible

Code Snippet

declare @.t table ( cid int, cnum int)
insert @.t select 1, 1
insert @.t select 2, 1
insert @.t select 3, 1
insert @.t select 4, 0
insert @.t select 5, 0

select * from @.t

select cid,
case cnum
when 1 then 0
when 0 then 1
end
from @.t

No comments:

Post a Comment