If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > compare null with null

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-10-06, 19:08
jinsezh jinsezh is offline
Registered User
 
Join Date: Aug 2006
Posts: 33
Question compare null with null

Hi there,

I want to compare source.enddate with target.enddate, they should be both NULL or the same value.

If I write " select * from source, target where source.enddate = target.enddate", it will not return the record which the two columns are both NULL.

So I wonder which is the easiest way to compare them.

Thanks,
jinse
Reply With Quote
  #2 (permalink)  
Old 10-10-06, 19:36
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
COALESCE(source.enddate,'1600-01-01')=COALESCE(target.enddate,'1600-01-01')
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 10-11-06, 05:09
umayer umayer is offline
Registered User
 
Join Date: Dec 2005
Posts: 273
try:

select * from source, target where source.enddate IS NOT DISTINCT FROM target.enddate

... IS [NOT] DISTINCT FROM ... is available for DB2 for z/OS V8 ( maybe it's also available for other platforms )
Reply With Quote
  #4 (permalink)  
Old 10-11-06, 12:20
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Code:
SELECT *
FROM   source, target
WHERE  source.enddate = target.enddate
OR     (source.enddate IS NULL
        AND
        target.enddate IS NULL
       )
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
  #5 (permalink)  
Old 10-11-06, 12:24
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Yet another one (might or might not be more performant than the others):
Code:
SELECT *
FROM   source INNER JOIN target
       ON source.enddate = target.enddate
UNION ALL
SELECT *
FROM   (SELECT * FROM source WHERE enddate IS NULL),
       (SELECT * FROM target WHERE enddate IS NULL)
Note that the latter join is actually a cross join!
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On