need to convert string 030308 into smalldatetime

Posted on 2009-04-14
Last Modified: 2012-05-06
when using the below query I get the error 'Arithmetic overflow error converting expression to data type smalldatetime.'

UPDATE    tblCourseHistory
SET              Starting_Date = RIGHT(Course_Code, 6)
WHERE     (Starting_Date IS NULL)

Starting_Date has a datatype of smalldatetime
Course_Code has a dataype of nvarchar
Question by:NevSoFly
  • 2

Expert Comment

Comment Utility

Starting_Date = CAST(RIGHT(Course_Code,6) AS SMALLDATETIME)

Expert Comment

Comment Utility
The other thing that may be going on is if Course_Code does not have at leas 6 characters. You may want to check your string length before making the assignment.
LVL 142

Accepted Solution

Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
this format will not "work" directly for cast/convert:

so, a bit of manual work will do:
UPDATE    tblCourseHistory
SET              Starting_Date = CONVERT(datetime,   RIGHT(Course_Code, 2)  + LEFT(RIGHT(Course_Code, 6), 4),   12)
WHERE     (Starting_Date IS NULL)

Open in new window


Author Closing Comment

Comment Utility
Thank you

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Dynamics crm 2011 8 43
ms sql stored procedure 22 74
SQL Performance optimisation - selecting as a column 29 25
Report Builder 9 22
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now