December 1, 2010 at 5:16 am
Hi,
select GR.NumDoc As Query1 from GR Where GR.NumDoc Not In (Select FactL.NDoc from FactL)
select FactL.NDoc As Query2 from FactL Where FactL.NDoc = 'GRM20611675'
select GR.NumDoc As Query3 from GR Where GR.NumDoc = 'GRM20611675'
I expected:
Query1 = 'GRM20611675'
Query2 =
Query3 = 'GRM20611675'
I get:
Query1 =
Query2 =
Query3 = 'GRM20611675'
Anyone can explain.
Tkx
December 1, 2010 at 5:32 am
when you use NOT IN, you have to prevent NULLs in your dataset:
change query1 to this, and you'll get the expected resultsi think.
select GR.NumDoc As Query1 from GR Where GR.NumDoc Not In (Select FactL.NDoc from FactL WHERE FactL.NDoc IS NOT NULL)
Lowell
December 1, 2010 at 5:34 am
Hi,
Figure it out.
select GR.NumDoc As Query1 from GR Where GR.NumDoc Not In (Select ISNULL(FactL.NDoc,'') from FactL)
Query1='GRM20611675'
As there as NULL values in FactL.NDoc it seems the NOT IN gets confused.
Why?
Tkx
December 1, 2010 at 5:35 am
Tkx Lowell
December 1, 2010 at 5:38 am
the why is easy; NOT IN requires it a comparison to each value in the sub-select.
really that is the same as saying :
WHERE GR.NumDoc <> 1
AND GR.NumDoc <> 2
AND GR.NumDoc <> NULL
...
since nulls appear int he dataset, and comparing a value to null is undefined, no results return.
Lowell
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply