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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Update based on two conditions

Author  Topic 

venkath
Posting Yak Master

202 Posts

Posted - 2006-10-05 : 10:19:13
Hi all

i need to update two columns in a table based on two conditions

UPDATE COMPANY_TYPE
SET COMP_PUB_ID_OPTION_CODE = 'REQ'
WHERE ASK_FOR_PUB_ID ='-1'

UPDATE COMPANY_TYPE
SET COMP_PUB_ID_OPTION_CODE = 'OPT'
WHERE ASK_FOR_PUB_ID ='0'

What i wanted to ask is..can i replace the above two update statements with single update statement
Thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-10-05 : 10:29:24
[code]
UPDATE COMPANY_TYPE
SET COMP_PUB_ID_OPTION_CODE = case when ASK_FOR_PUB_ID = '-1' then 'REQ'
when ASK_FOR_PUB_ID = '0' then 'OPT'
end,
WHERE ASK_FOR_PUB_ID in ('0', '-1')
[/code]


KH

Go to Top of Page

venkath
Posting Yak Master

202 Posts

Posted - 2006-10-05 : 11:00:42
Thanks.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-05 : 11:16:26
or If it is for display, just use them in Select

Select columns,case when ASK_FOR_PUB_ID = '-1' then 'REQ'
when ASK_FOR_PUB_ID = '0' then 'OPT'
else ASK_FOR_PUB_ID end
from table


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -