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
 General SQL Server Forums
 New to SQL Server Programming
 IF syntax

Author  Topic 

kirknew2SQL
Posting Yak Master

194 Posts

Posted - 2008-01-16 : 22:06:28
I have a table in which I need to populate one column with a value from one of the other columns. As soon as a value ios found the remaining columns don't need to be evaluated.

What is the correct syntax for this IF? Or is there a better way to do this?

UPDATE MyTable
SET FillPhone =
If !ISEMPTY(FillPhone)
Phone
If !ISEMPTY(FillPhone)
NewSo_Phone
IF !ISEMPTY(FillPhone)
MediC_Phone
IF !ISEMPTY(FillPhone)
Insur_Phone

thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-16 : 22:14:54
[code]UPDATE MyTable
SET FillPhone = coalesce(FillPhone, Phone, NewSo_Phone, MediC_Phone, Insur_Phone)[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

kirknew2SQL
Posting Yak Master

194 Posts

Posted - 2008-01-16 : 22:25:12
Had to go look that one up. :) I haqd never heard of that function. Thank you
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-16 : 22:41:29
basically it is isnull that accept more parameters

http://msdn2.microsoft.com/en-us/library/ms190349.aspx


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

kirknew2SQL
Posting Yak Master

194 Posts

Posted - 2008-01-17 : 11:16:36
Thanks for the URL. I learn something new every day.
Go to Top of Page
   

- Advertisement -