Home Forums SQL Server 2008 T-SQL (SS2K8) Pulling incorrect records using date range in where clause RE: Pulling incorrect records using date range in where clause

  • Btw, you should < on date/datetime, not <=, as below. Otherwise you risk missing rows, especially if the data type of the underlying column changes (to datetime from smalldate, datetime2 from datetime, etc.).

    Also, 'YYYYMMDD' is the only 100% safe date format (excluding obscure versions with 'T' in them).

    ath_postdate >= '20130101' and

    ath_postdate < '20130106'

    Edit: I'm assuming it was Jan 05 not May 01 (demonstrating the ambiguity of the other format :-)).

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.