How to make sure two different date fields are the same in a query

  • For example, I would like for DateField A to be '12/1/15' and Datefield B to be '12/1/15'. I'm looking for customers that have the same dates for those fields. is it as simple as:

    where A.DateFilled >= '12/01/2015'

    and A.DateFilled < '12/02/2015'

    and B.DateFilled >= '12/01/2015'

    and B.DateFilled < '12/02/2015'

  • I suspect we might need a little more information. When I read

    I'm looking for customers that have the same dates for those fields.

    I'm thinking all you want is to see which ones have matching dates.

    Therefore...

    WHERE A.DateFilled = B.DateFilled

    But something tells me that's not quite what your asking for. Can you provide some sample data and desired output?


    SELECT quote FROM brain WHERE original = 1
    0 rows returned

  • I am 99% confident that there is a TIME element in the date fields that is messing things up. Assuming you don't CARE about the time, you have two options:

    1) What you showed should work.

    2) Brute force and inefficient way is to case the field(s) to a date datatype, which will lop off the time, and then do a simple equals filter.

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply