Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

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

$
0
0

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 StagingTable 
Purpose: I am trying to flag invalid order_dt and if possible to fix/correct before it goes to destination tables


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>