Environment: SQL Server 2008 R2
Problem: An error message occurred "The conversion of a varchar data type to a datetime data type resulted in an out-of-range value", when I was trying to flag invalid date.
The following data are stored in the order_dt
order_dt
Apr 3 2013 12:00AM
20130229
Apr 3 2013 12:00AM
Code:
SELECT CASE WHEN order_dt >= getdate() THEN 'date leap' WHEN ISDATE(order_dt) = 0 THEN 'invalid date' END AS 'Date' FROM StagingTablePurpose: I am trying to flag invalid order_dt and if possible to fix/correct before it goes to destination tables