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)
 join with ISNULL?

Author  Topic 

magmo
Aged Yak Warrior

558 Posts

Posted - 2012-01-30 : 06:09:03
Hi

I have this ....


ISNULL(dbo.tbl_Login.LanguageID, ISNULL(dbo.tbl_Login.LanguageID, 1))
AS LanguageID



That give a default value if both columns are null which is fine, but I also need to use that "LanguageID" to join in the table "Language" and retrieve a value from that table based on the "LanguageID". How would I do that?

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2012-01-30 : 07:02:35
Although the tables and column names are the same (which I guess you didn't mean, but if you did, why?!?):

COALESCE(dbo.tbl_Login.LanguageID, dbo.tbl_Login.LanguageID, 1)
Go to Top of Page

magmo
Aged Yak Warrior

558 Posts

Posted - 2012-01-30 : 07:11:41
Hi

Youre absolutly right, thats not correct, my mistake. It supposed to look like this...
ISNULL(dbo.tbl_Login.LanguageID, ISNULL(dbo.tbl_Customer.LanguageID, 1))
AS LanguageID
But where do I insert the coalesce part?
Go to Top of Page

magmo
Aged Yak Warrior

558 Posts

Posted - 2012-01-30 : 07:51:59
ok, coalesce is just an alternative to my approach, any ideas to my original question?
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2012-01-30 : 11:37:28
You can use that on your join condition, you will not be able to use an index on the field though.

join
your other table
on table1.languageid = COALESCE(tbl_Login.LanguageID, tbl_Customer.LanguageID, 1)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-30 : 11:42:04
quote:
Originally posted by magmo

ok, coalesce is just an alternative to my approach, any ideas to my original question?


why not split it up to two seperate joins?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -