Solved

need to convert string 030308 into smalldatetime

Posted on 2009-04-14
4
374 Views
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
0
Comment
Question by:NevSoFly
  • 2
4 Comments
 
LVL 6

Expert Comment

by:ViceroyFizzlebottom
ID: 24141532
Try:

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

Expert Comment

by:ViceroyFizzlebottom
ID: 24141580
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.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24141680
this format will not "work" directly for cast/convert:
http://msdn.microsoft.com/en-us/library/ms187928.aspx

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

0
 

Author Closing Comment

by:NevSoFly
ID: 31570103
Thank you
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tempdb log keep growing 7 35
SQL Log size 3 20
What is the best way to use power bi and ssrs 3 27
Need help in debugging a UDF results 7 29
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

820 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