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 2005 Forums
 Transact-SQL (2005)
 update with case?

Author  Topic 

albertkohl
Aged Yak Warrior

740 Posts

Posted - 2008-05-19 : 19:36:04
Okay, so i have to check to tables against each other.

if record in Table1 IS NOT in Table2 i want to set dnc to '' or null if record in Table1 IS in Table2 i want to set dnc to 'Y'


currently, i have to do two passes. i was wonder if anyone would help me make this one statement.

Thanks!


update t1
set dnc = ''
from test_new.dbo.consumer t1
go

update t1
set dnc = 'y'
from test_new.dbo.consumer t1
inner join residential.dbo.dnc on tl1=phone
go

singularity
Posting Yak Master

153 Posts

Posted - 2008-05-19 : 22:42:20
update t1
set t1.dnc = case when d.dnc is null then null else 'Y' end
from test_new.dbo.consumer t1
left join residential.dbo.dnc d on t1.tl1=d.phone
Go to Top of Page
   

- Advertisement -