Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 SQL Server 2008 - CAST in Where clause

Author  Topic 

agipson30
Starting Member

5 Posts

Posted - 2013-08-06 : 15:46:12
Hi,

My company is in the process of upgrading several SQL 2000 servers to 2008, However, after a successful upgrade of one server we are having a issue ithe the second upgrade.

The error is ‘Msg 8114, Level 16, State 5, Line 1
Error converting data type nvarchar to numeric.’ I’ve been able to recreate the error with the below code.

select ResponseText,CAST(ResponseText as decimal(9,4))
from ah_member_responses_detail
Where account = XXXXXXX
and ResponseID in
(select ResponseID
from ah_member_responses
Where account = XXXXXXX
and Question_ID in (258,2506,46)
AND CAST(ResponseText AS DECIMAL(9,4)) <> 0)

The last statement is causing the error but on the other upgraded database we do not get the error.

Can you help me with why this could be the case. Was something not upgraded correctly?

Alonzo Gipson

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2013-08-06 : 15:48:05
Sounds like you've got bad data. Check the column for non-numeric data.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

agipson30
Starting Member

5 Posts

Posted - 2013-08-06 : 15:59:10
quote:
Originally posted by tkizer

Sounds like you've got bad data. Check the column for non-numeric data.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog



Yes, that data is there and on the first upgraded server but that server does not have a problem.

Alonzo Gipson
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2013-08-06 : 16:16:11
What is the compatibility level for both upgraded databases?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

agipson30
Starting Member

5 Posts

Posted - 2013-08-06 : 16:43:23
80

Alonzo Gipson
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2013-08-06 : 16:45:50
See if changing it to 100 helps. 80 is SQL Server 2000.

Also, compare SELECT @@VERSION on both. Maybe one has a higher hotfix/SP.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

agipson30
Starting Member

5 Posts

Posted - 2013-08-06 : 16:49:55
They both have the same version. Also, since we are upgrading from 2000 to 2008 should it tay at (80). We skipped 2005 so we are the last of the dinosaurs.



Alonzo Gipson
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2013-08-06 : 16:51:51
You should change the compatibility level to the new version if your application can support it so that you can use the new features.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

agipson30
Starting Member

5 Posts

Posted - 2013-08-06 : 16:58:58
Thank you, I changed the compatibility level and no changes and the same error happens.

Alonzo Gipson
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2013-08-06 : 17:41:57
Sorry I'm out of ideas. They both should error if they both have bad data (non-numeric). I can't explain why the first one doesn't error, but they both should. You'll need to fix the data for this to work. You can open a case with MS to determine why one succeeds and one fails if someone else doesn't have an answer in here.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -