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 query get data from same tables another col

Author  Topic 

reddymade
Posting Yak Master

165 Posts

Posted - 2008-07-11 : 10:09:02
I want to fill data to a column(SpanishLabel) from the same tables another field called englishlabel, the condition is if the spanishlabel = NULL then fill the englishlabel columns data to it.

Update Tab_ccsnetLabels set Spanishlabel= t2.englishlabel from tab_ccsnetlabels t1 inner join tab_ccsnetlabels t2
on t1.labelkey = t2.labelkey and t1.spanishlabel = NULL

Thank you very much for the helpful information.

rohitkumar
Constraint Violating Yak Guru

472 Posts

Posted - 2008-07-11 : 10:20:03
where's the question?

UPDATE Tab_ccsnetLabels SET Spanishlabel = COALESCE(Spanishlabel, englishlabel)
Go to Top of Page

reddymade
Posting Yak Master

165 Posts

Posted - 2008-07-11 : 10:21:47
Thanks,

But i don't see the condition for where spanishlabel=NULL


quote:
Originally posted by rohitkumar

where's the question?

UPDATE Tab_ccsnetLabels SET Spanishlabel = COALESCE(Spanishlabel, englishlabel)

Go to Top of Page

rohitkumar
Constraint Violating Yak Guru

472 Posts

Posted - 2008-07-11 : 10:46:23
read this

http://msdn.microsoft.com/en-us/library/ms190349.aspx
Go to Top of Page

bjoerns
Posting Yak Master

154 Posts

Posted - 2008-07-11 : 12:02:00
NULL never equals anything!

Update Tab_ccsnetLabels set Spanishlabel= t2.englishlabel from tab_ccsnetlabels t1 inner join tab_ccsnetlabels t2
on t1.labelkey = t2.labelkey and t1.spanishlabel IS NULL

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-12 : 00:58:11
quote:
Originally posted by bjoerns

NULL never equals anything!

Update Tab_ccsnetLabels set Spanishlabel= t2.englishlabel from tab_ccsnetlabels t1 inner join tab_ccsnetlabels t2
on t1.labelkey = t2.labelkey and t1.spanishlabel IS NULL




No need of the join.just use COALESCE as suggested by Rohit.
Go to Top of Page
   

- Advertisement -