[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

need to convert string 030308 into smalldatetime

Posted on 2009-04-14
4
Medium Priority
?
408 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

656 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