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
 is this right logic

Author  Topic 

jpockets
Starting Member

45 Posts

Posted - 2007-06-12 : 11:53:53
What i'm trying to do is if this column dt.IN_DIV_NO is populated take that value first if it's null than rr.AIQ_R_DIVISION_NO and if that column is null than rr.F_DIVISION_NO.

This is what i came up with, will it evaluate the way i need it to?

case When dt.IN_DIV_NO is not null then dt.IN_DIV_NO else case when rr.AIQ_R_DIVISION_NO is null then rr.F_DIVISION_NO end end as Current_DIV 


Thank-you

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-06-12 : 11:56:21
Why not Coalesce()?

Coalesce(dt.IN_DIV_NO, rr.AIQ_R_DIVISION_NO, rr.F_DIVISION_NO)


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-06-12 : 11:58:16
[meh]

[/meh]

COALESCE(dt.IN_DIV_NO, rr.AIQ_R_DIVISION_NO, rr.F_DIVISION_NO)


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-06-12 : 11:58:37
yeah something like this:
 Current_DIV = CASE WHEN dt.IN_DIV_NO IS NULL THEN ( CASE WHEN rr.AIQ_R_DIVISION_NO IS NULL THEN rr.F_DIVISION_NO ELSE rr.AIQ_R_DIVISION_NO END) ELSE dt.IN_DIV_NO END 


Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

jpockets
Starting Member

45 Posts

Posted - 2007-06-12 : 12:24:25
Thanks for the help, i never knew about the COALESCE before did some research and it's excatly what i need, thank-you for the help!
Go to Top of Page
   

- Advertisement -