Solved

need to convert string 030308 into smalldatetime

Posted on 2009-04-14
4
384 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
[Unsupported] SQL Update in CRM 2011 Database 19 60
SQL Server Agent Job Error 13 74
SQL Server how to create a DYNAMIC TABLE? 11 49
mssql 7 32
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.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

737 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