date in select statement

  • I have a datetime column which contains dates such as

    2014-12-28 08:52:02.920

    The database collation is "Latin1_General_CI_AS"

    how do I write "select * from table where datetimecolumn = ..." ?

    whatever I tried so far doesn't work.

    thanks

    -Michael

  • SELECT * FROM TableName WHERE DateTimeColumn = '2014-12-28 08:52:02.920'

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • GilaMonster (12/30/2014)


    SELECT * FROM TableName WHERE DateTimeColumn = '2014-12-28 08:52:02.920'

    Msg 242, Level 16, State 3, Line 1

    The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

  • veloopity (12/30/2014)


    GilaMonster (12/30/2014)


    SELECT * FROM TableName WHERE DateTimeColumn = '2014-12-28 08:52:02.920'

    Msg 242, Level 16, State 3, Line 1

    The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

    Take out the dashes.

    SELECT * FROM TableName WHERE DateTimeColumn = '20141228 08:52:02.920'

  • ah, that works !! 1000 thanks

    -mpe

    🙂

Viewing 5 posts - 1 through 4 (of 4 total)

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