Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
scelamko
Constraint Violating Yak Guru
309 Posts |
Posted - 2006-10-26 : 10:53:01
|
guys,I have situation here where I have to update role = 1 where role = 2 and update role = 2 where role = 1ID ROLE____________1 12 23 14 2It should be transformed to ID ROLE____________1 22 13 24 1I think this can be done only using case statement which doesnt seem to work for meany suggestions/inputs would helpThanks |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-10-26 : 10:54:38
|
[code]update tableset ROLE = case when ROLE = 1 then 2 else 1 end[/code] KH |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-26 : 10:59:09
|
update table set role = 3 - rolePeter LarssonHelsingborg, Sweden |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-10-26 : 11:00:40
|
quote: Originally posted by Peso update table set role = 3 - rolePeter LarssonHelsingborg, Sweden
Good idea  KH |
 |
|
scelamko
Constraint Violating Yak Guru
309 Posts |
Posted - 2006-10-26 : 11:05:42
|
quote: Originally posted by Peso update table set role = 3 - rolePeter LarssonHelsingborg, Sweden
great idea!!! |
 |
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-10-26 : 11:07:21
|
Job interview question?I would do it this way, just in case there is some value besides 1 or 2 in ROLE.update MyTableset ROLE = case when ROLE = 1 then 2 when ROLE = 2 then 1 else ROLE end CODO ERGO SUM |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-26 : 11:25:11
|
update table set role = 3 - rolewhere role in (1, 2)Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|