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 |
|
macsterling
Yak Posting Veteran
56 Posts |
Posted - 2009-01-24 : 21:47:21
|
| update table set column = case when another_column = '1' then 'A' when another_column = '2' then 'B' when another_column = '3' then 'C' endWhen another_column = something else, it puts null into column. I only want to change column when any of those three conditions are metWhat do I put in the else statement to make it leave column alone |
|
|
macsterling
Yak Posting Veteran
56 Posts |
Posted - 2009-01-24 : 22:09:34
|
| I figured it out - I had something commented out - Thanks anyway |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-25 : 04:45:50
|
| not sure how you fixed it. but there are two ways1.add else condition as else column2. put a where condition where another_column in ('1','2','3') |
 |
|
|
Kokkula
Starting Member
41 Posts |
Posted - 2009-01-28 : 06:20:41
|
| Try thisupdate tableset column = casewhen another_column = '1' then 'A'when another_column = '2' then 'B'when another_column = '3' then 'C'ELSE column endWhen another_column = something--Thanks,Pavan |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-28 : 08:55:29
|
quote: Originally posted by Kokkula Try thisupdate tableset column = casewhen another_column = '1' then 'A'when another_column = '2' then 'B'when another_column = '3' then 'C'ELSE column endWhen another_column = something--Thanks,Pavan
whats the purpose of last when? |
 |
|
|
Kokkula
Starting Member
41 Posts |
Posted - 2009-01-29 : 08:13:34
|
| Thanks Visakh for pointing to it sgould be actually Where insted of when.UPDATE tableSET column = CASEWHEN another_column = '1' then 'A'WHEN another_column = '2' then 'B'WHEN another_column = '3' then 'C'ELSE column ENDWHERE another_column = something <Where Condition>--Thanks,Pavan |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-01-29 : 08:23:37
|
A WHERE clause will speed things up.And you also with a WHERE don't need an ELSE part in the CASE statement. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|
|
|