troubleshooting Question

SQL Syntax - convert varchar yymmdd to varchar yyyymmdd

Avatar of robthomas09
robthomas09 asked on
Microsoft SQL Server 2005SQL
8 Comments3 Solutions1775 ViewsLast Modified:
Hello experts,

I have a desire to convert a column called recall_date to varchar yyyymmdd, which currently is formatted yymmdd.  

The recall_date column has plenty of null values so we want to filter those out. When I run the below script I receive the error:

Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type datetime.
The statement has been terminated.

I realize that my 103 is a datetime convert - but I can go from datetime to yyyymmdd which is why I did that.  There is likely an easier way.


update demo_out2
set recall_date = 
case when recall_date is not null 
and len(recall_date) = 6
then CONVERT(varchar, CAST(recall_date AS DATETIME), 103) 
else '' end
Sharath S
Data Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros