![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hello - I have a strange problem when casting value under 64-bit sql server 2005 vs under 32-bit sql server 2005. I got two servers. One has 32-bit SQL server 2005 standard edition (version 9.00.3073.00) on Windows NT 5.2 (3790) with NT INTEL x86. The second server has 64-bit SQL server Enterprise edition (version 9.00.4035.00) on Windows NT 5.2 (3790) with NT AMD64. The problem came when I tried to cast value under 32-bit SQL server 2005, the result gets queried out. But when the same sql got run, it prompted conversion error - "Error converting data type varchar to numeric." under the 64-bit server. I tried cleaned up the data and it still gives the same error. Please show us how to reproduce this symptom. You need to provide a script |
#3
| |||
| |||
|
|
xo wrote: Hello - I have a strange problem when casting value under 64-bit sql server 2005 vs under 32-bit sql server 2005. I got two servers. *One has 32-bit SQL server 2005 standard edition (version 9.00.3073.00) on Windows NT 5.2 (3790) with NT INTEL x86. The second server has 64-bit SQL server Enterprise edition (version 9.00.4035.00) on Windows NT 5.2 (3790) with NT AMD64. The problem came when I tried to cast value under 32-bit SQL server 2005, the result gets queried out. *But when the same sql got run, *it prompted conversion error - "Error converting data type varchar to numeric." under the 64-bit server. I tried cleaned up the data and it still gives the same error. Please show us how to reproduce this symptom. You need to provide a script that we can run on our servers to see the error you are getting. If the problem occurs when using variables, that would enable you to easily create a repro script: declare @v1 <somedatatype>, @v2 <someotherdatatype>; set @v1=<somevalue>; set @v2=cast(@v1 as <someotherdatatype>); Replace the <...>s with the actual data types and values required to reproduce your symptom and post it here. |
#4
| |||
| |||
|
|
I have a strange problem when casting value under 64-bit sql server 2005 vs under 32-bit sql server 2005. I got two servers. One has 32-bit SQL server 2005 standard edition (version 9.00.3073.00) on Windows NT 5.2 (3790) with NT INTEL x86. The second server has 64-bit SQL server Enterprise edition (version 9.00.4035.00) on Windows NT 5.2 (3790) with NT AMD64. The problem came when I tried to cast value under 32-bit SQL server 2005, the result gets queried out. But when the same sql got run, it prompted conversion error - "Error converting data type varchar to numeric." under the 64-bit server. I tried cleaned up the data and it still gives the same error. |
#5
| |||
| |||
|
|
xo (xo555... (AT) gmail (DOT) com) writes: I have a strange problem when casting value under 64-bit sql server 2005 vs under 32-bit sql server 2005. I got two servers. *One has 32-bit SQL server 2005 standard edition (version 9.00.3073.00) on Windows NT 5.2 (3790) with NT INTEL x86. The second server has 64-bit SQL server Enterprise edition (version 9.00.4035.00) on Windows NT 5.2 (3790) with NT AMD64. The problem came when I tried to cast value under 32-bit SQL server 2005, the result gets queried out. *But when the same sql got run, *it prompted conversion error - "Error converting data type varchar to numeric." under the 64-bit server. I tried cleaned up the data and it still gives the same error. This is has nothing to do with 32- or 64-bit per se. You just happen to get different execution plans on the two machines. If you have a query like: SELECT cast(str AS int) FROM * tbl WHERE *isnumeric(str) = 1 The query may or may not fail, depending on when isnumeric is evaluated. You could argue that from how SQL is defined, the query should never fail, but that is not how Microsoft has designed it. (And they are not alone. I once read a blogpost about this problem on Oralce.) The almost safe way is to do: SELECT CASE WHEN isumeric(str) = 1 THEN cast(str AS int) END FROM * tbl WHERE *isnumeric(str) = 1 I say "almost safe", because isnumeric may approve of values that cannot be cast to int. The next version of SQL Server 100% safe way: SELECT try_convert(int, str) FROM * tbl WHERE *try_convert(int, str) IS NOT NULL try_convert returns NULL if the convert fails. This function is long- awaited! -- Erland Sommarskog, SQL Server MVP, esq... (AT) sommarskog (DOT) se Links for SQL Server Books Online: SQL 2008:http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx SQL 2005:http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx |
#6
| |||
| |||
|
|
Thanks for the respond. I would like to provide the error message so hopefully it will help. |
#7
| |||
| |||
|
|
The error seems to be caused by the last line. Add'l info - FLODS_ID is (PK, numeric (18,0), not null) and OBJECT_ID (varchar(80), null) Below is the sql - snip Thanks in advance |
#8
| |||
| |||
|
|
xo (xo555... (AT) gmail (DOT) com) writes: Thanks for the respond. * I would like to provide the error message so hopefully it will help. I know perfectly well what the error is. It's a very common question on the newsgroups. My previous post presented the cure for the problem, so know you know how to fix your query! (And let's hope that isnumeric does not find any false positives! -- Erland Sommarskog, SQL Server MVP, esq... (AT) sommarskog (DOT) se Links for SQL Server Books Online: SQL 2008:http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx SQL 2005:http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx |
#9
| |||
| |||
|
|
I am bound by the decision maker not to change the structure of the view but to find out why it is working on the old 32-bit SQL server 2005 but not working the new 64-bit SQL server. Thanks |
![]() |
| Thread Tools | |
| Display Modes | |
| |