March 6, 2013 at 6:58 am
select cast(COL1 as datetime) from TABLE where COL1<>'' and isdate(COL1) =1 and
cast(COL1 as datetime) < (DATEADD(YY, -3, GETDATE()))
above query gives the error
Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type datetime.
COL1 is an nvarchar column
Any idea why?
March 6, 2013 at 7:08 am
Definitely something to do with the kind of data you have inside the table. Could you provide some of the data inside the table Table for COL1 ?
March 6, 2013 at 7:27 am
08/17/2009 in mm/dd/yyyy format. If you see the query, i filter out invalid dates, which are nulls, blanks etc
March 6, 2013 at 7:34 am
You have something in there that can't be cast as a datetime and it is failing. Your where clause also casts Col1 as a datetime so if there is something in the table it will throw an exception.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply