Results 1 to 3 of 3

Thread: Simple Select with date clause [Resolved]

  1. #1

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Simple Select with date clause [Resolved]

    I am running MSSQL 2K SP3 and using a very simple select statement to grab some files from a table:

    Code:
    SELECT * FROM [Hours] WHERE InputDate = '11/16/2004' AND CType = 1 AND ReadNum = 2 ORDER BY CellID
    The datatype for the field is smalldatetime and I've tried several combinations of dates and times, and even used the LIKE operator. The only way I can get it to work is to use the BETWEEN operator and check for the day before and the day after.

    Why isn't this working??? And yes, there are records with that date and the records meet the other clause needs. If I take the date portion out, it works but grabs more data than I want.



    Last edited by ober0330; Nov 18th, 2004 at 10:16 AM.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  2. #2
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016
    Check the actual values of the InputDate field. Chances are they are also storing the time. If that is the case, then you are effectively comparing '11/18/2004 09:07:33' to '11/18/2004 00:00:00', which doesn't match. One option is to change the comparison to:
    Code:
    SELECT * 
    FROM [Hours]
    WHERE Convert(VarChar(10), InputDate, 101) = '11/16/2004' 
    AND CType = 1 
    AND ReadNum = 2 
    ORDER BY CellID
    That would cause the date to be converted to the mm/dd/yyyy format that you could use to compare against your parameter.
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  3. #3

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Thumbs up

    That's why I love this board. Thanks!
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

Posting Permissions

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



Click Here to Expand Forum to Full Width