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.
Author |
Topic |
magmo
Aged Yak Warrior
558 Posts |
Posted - 2012-01-30 : 06:09:03
|
HiI 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) |
 |
|
magmo
Aged Yak Warrior
558 Posts |
Posted - 2012-01-30 : 07:11:41
|
HiYoure 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 LanguageIDBut where do I insert the coalesce part? |
 |
|
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? |
 |
|
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.joinyour other tableon table1.languageid = COALESCE(tbl_Login.LanguageID, tbl_Customer.LanguageID, 1) |
 |
|
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 MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|