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 |
SQLS33ker
Starting Member
16 Posts |
Posted - 2013-07-24 : 01:03:52
|
Hi there,When you join tables based on a common join in this syntax:T1.col1 = T2.col1 OR (T1.col1 IS NULL and T2.col1 IS NULL);What do texts within the bracket tell the server do? The textbook says we are saying to treat NULLs as equal. Does that mean all the null values will participate in the join? If null = null, then that's a match?Thanks |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-24 : 01:47:44
|
Yes..it just means when there's a NULL on both T1.Col1 and T2.Col1 then that records will matched against each otherNULL=NULL is never true so to treat them as same we need to use either above method oruse ISNULL or COALESCE function to convert them to a common default valuelike ISNULL(T1.col1,-1) = ISNULL(T2.col1,-1) if intISNULL(T1.col1,'') = ISNULL(T2.col1,'') if varchar etc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
SQLS33ker
Starting Member
16 Posts |
Posted - 2013-07-24 : 01:51:48
|
quote: Originally posted by visakh16 Yes..it just means when there's a NULL on both T1.Col1 and T2.Col1 then that records will matched against each otherNULL=NULL is never true so to treat them as same we need to use either above method oruse ISNULL or COALESCE function to convert them to a common default valuelike ISNULL(T1.col1,-1) = ISNULL(T2.col1,-1) if intISNULL(T1.col1,'') = ISNULL(T2.col1,'') if varchar etcgreat thanks.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs
|
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-24 : 02:26:31
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|