Advertisement

04.11.2008 at 05:15AM PDT, ID: 23314778
[x]
Attachment Details

Difference between CONVERT from varchar and CONVERT from nvarchar

Asked by BebbieSJ in SQL Server 2005

Tags: Microsoft, SQL Server, 2005, Msg 8115 arithmetic overflow converting expression to smalldatetime data type

Hello,

Can anyone explain the difference between a SQL Server 2005 conversion from varchar and nvarchar to datetime or smalldatetime? Look at the following example:

SELECT DISTINCT HEDTE, CONVERT(smalldatetime, HEDTE, 112)
FROM ECHECL
ORDER BY HEDTE

This returns the error: Msg 8115 arithmetic overflow converting expression to smalldatetime data type. The column HEDTE is of type nvarchar(8).

The following modification solves the problem, but I don't understand why:

SELECT DISTINCT HEDTE, CONVERT(smalldatetime, CAST(HEDTE AS varchar(8)), 112)
FROM ECHECL
ORDER BY HEDTE

This returns the correct results. The data underneath has not changed. What is the difference between converting the same string from varchar to smalldatetime and from nvarchar to smalldatetime, when I even provide the input format of the string expression in the CONVERT function?

Any explanation is very appreciated!

Thanks,
Sebastian

PS: For reference the result set of the succesful query is attached as file.Start Free Trial
Attachments:
 
 
[+][-]04.11.2008 at 05:21AM PDT, ID: 21333459

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 05:30AM PDT, ID: 21333522

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 05:34AM PDT, ID: 21333547

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: SQL Server 2005
Tags: Microsoft, SQL Server, 2005, Msg 8115 arithmetic overflow converting expression to smalldatetime data type
Sign Up Now!
Solution Provided By: chapmandew
Participating Experts: 3
Solution Grade: A
 
 
[+][-]04.11.2008 at 05:51AM PDT, ID: 21333706

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 05:52AM PDT, ID: 21333705

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04.11.2008 at 07:03AM PDT, ID: 21334345

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 07:08AM PDT, ID: 21334397

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628