Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2006
    Posts
    33

    Question Unanswered: 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

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    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.

  3. #3
    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 )

  4. #4
    Join Date
    Sep 2004
    Location
    Belgium
    Posts
    1,126
    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/

  5. #5
    Join Date
    Sep 2004
    Location
    Belgium
    Posts
    1,126
    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/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •