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)
 RE inner join and null issue

Author  Topic 

agarwasa2008
Posting Yak Master

109 Posts

Posted - 2009-12-11 : 13:07:28
select * from table1 a
inner join table2 b on b.id = a.id
inner join table3 c on c.col1 = a.col1
where a.name = 'something'

The issue is that id can contain null values in table1, table 2 and
col1 can contain null values in table1 and table3.

SA

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-12-11 : 13:11:37
ok and you want to match nulls as well from them?
Go to Top of Page

agarwasa2008
Posting Yak Master

109 Posts

Posted - 2009-12-11 : 13:34:47
No if it is null I want to obviously ignore those values.


SA
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-12-11 : 13:36:45
it will ignore nulls by default
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-12-11 : 13:39:48
b/w what is your ansi nulls setting status? check using below query

EXEC sp_dboption 'yourdatabase', 'ANSI nulls'
Go to Top of Page

agarwasa2008
Posting Yak Master

109 Posts

Posted - 2009-12-11 : 13:42:43
Yes. But if 'id' and 'col1' is null there are values in table1 that need to be displayed. Its giving 0 rows which is incorrect

SA
Go to Top of Page

agarwasa2008
Posting Yak Master

109 Posts

Posted - 2009-12-11 : 13:44:29
okay that query :
EXEC sp_dboption 'yourdatabase', 'ANSI nulls'

gives "OFF"

SA
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-12-11 : 13:47:03
then it comparison with NULLs evaluates to true.

b/w if your attempt is to display table1 rows regardless of match in others use left join
Go to Top of Page

agarwasa2008
Posting Yak Master

109 Posts

Posted - 2009-12-11 : 13:48:48
That was it! Thanks!


SA
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-12-11 : 13:49:29
welcome
Go to Top of Page
   

- Advertisement -