SQL Date Parsing Error

I am writing some SQL to pull data from our AS400 here at work. I was getting the error "Arithmetic overflow error converting expression to data type datetime." from the following code where date_column contained a date formatted like 20080930:

 year(date_column)

At first, I thought there was some bad data in the column. It turns out, the datatype was int as opposed to varchar like I had assumed. This fixed it:

 year(cast(date_column as varchar(8)))

TweetBacks
Comments (Comment Moderation is enabled. Your comment will not appear until approved.)


BlogCFC was created by Raymond Camden. This blog is running version 5.9.5. Contact Blog Owner