Forum Discussion

LisaRoby's avatar
LisaRoby
Frequent Visitor
5 years ago
Solved

Msg 241, Level 16, State 1, Line 1 Conversion failed when converting date and/or time from character

The following is my query, I am trying to convert from Oracle to SQL and I have hit a roadblock with this one. The line this is referring to is a datetime2 data type so I am unclear why there is an i...
  • v-luwang-msft's avatar
    5 years ago

    Hi LisaRoby ,

    Change    (trlr.dispatch_dte > convert(datetime, '7/29/2020 00:00:00', 126))  to the below:

    trlr.dispatch_dte>=cast('2020-07-29' as date)

    1. SELECT * FROM [master].[dbo].[trlr];

    2. SELECT * FROM [master].[dbo].[trlr] where (trlr.dispatch_dte > convert(datetime, '7/29/2020 00:00:00', 126));

    the same error as your's.

     

    3. SELECT *FROM [master].[dbo].[trlr] where trlr.dispatch_dte>=cast('2020-07-29' as date);

    successful.

     

    Don't forget to give thumbs up and accept this as a solution if it helped you!!!

     

    Best Regards

    Lucien