Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I need to to populare a column based oon the contents of another column. I thught an IF would be the right command but i can't get the syntex correct. Should I use an IF or should i use a different method?update MyTest set Action = IF status in ('Hospital Phone Number', 'Fax Tone', 'Wrong Phone Number- Not A Doctors Office', 'Number Not In Service', 'Unknown Home Answering Machine') then 'DELETE' elseif status in ('xxx', 'yyy') then 'OK'
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts
Posted - 2008-01-28 : 16:00:28
Use CASE.
UPDATE MYTESTSET ACTION=CASE WHEN STATUS IN (....) THEN 'DELETE' WHEN STATUS IN (....) THEN 'OK'END
Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED"
dinakar
Master Smack Fu Yak Hacker
2507 Posts
Posted - 2008-01-28 : 16:00:52
Use CASE.
update MyTestset Action = CASE WHEN [status] in ('Hospital Phone Number', 'Fax Tone', 'Wrong Phone Number- Not A Doctors Office', 'Number Not In Service', 'Unknown Home Answering Machine') then 'DELETE' WHEN [status] in ('xxx', 'yyy') then 'OK' END
Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts
Posted - 2008-01-28 : 16:01:36
try this update MyTestset Action = case when status in ('Hospital Phone Number', 'Fax Tone', 'Wrong Phone Number- Not A Doctors Office', 'Number Not In Service', 'Unknown Home Answering Machine') then 'DELETE' when status in ('xxx', 'yyy') then 'OK' end
kirknew2SQL
Posting Yak Master
194 Posts
Posted - 2008-01-28 : 16:06:21
Thanks for the help. I'll know the proper command now. :)