Null date

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pushaskhelp
    New Member
    • Jun 2010
    • 3

    Null date

    I have one table with id,name,submiss ion date and followup date.
    followup date may be null.
    i have to select id from this table where followupdate is less than given date.
    and if followup date is null then I have to select id from this table where submission date is less than given date.
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    A comparison to a NULL is meaningless.
    You could use COALESCE
    Code:
    WHERE given date >= COALESCE(followupdate,submission)

    Comment

    • debasisdas
      Recognized Expert Expert
      • Dec 2006
      • 8119

      #3
      then select it, what is the problem ?

      Comment

      • Jerry Winston
        Recognized Expert New Member
        • Jun 2008
        • 145

        #4
        Can you share your query?

        Comment

        • viktorka
          New Member
          • Jun 2010
          • 26

          #5
          Originally posted by b0010100
          Can you share your query?
          You can try to play around something like:

          SELECT * FROM table1 where followup < @date and followup is not null
          Union
          SELECT * FROM table1 where is not null and submissionDate < @date

          Comment

          • Jerry Winston
            Recognized Expert New Member
            • Jun 2008
            • 145

            #6
            Code Green said it best: "A comparison to a null is meaningless"

            Try using isNULL(field,'V alueIfNull'):

            Code:
            SELECT * FROM table1 where NOT isNull(followup,'NULL') = 'NULL' 
            AND
            followup < @date
            Union
            SELECT * FROM table1 where NOT isNull(submissionDate,'ThisDateISNULL') = 'ThisDateISNULL'
            AND 
            submissionDate < @date

            Comment

            Working...