Friday, February 17, 2012

Data Type conversion precedence problem

I heard that if you upgrade user database from SQL 7.0 to SQL 2000(latest SPs),
there is some data type conversion precedence problem and the same query
will produce different results on SQL 7.0 and SQL 2000.
I am sorry, I don't have any specific examples. If someone had this problem,
please advice me with some examples.
Thanks.
Strictly speaking I think your question is not about data type precedence,
which has stayed the same from SQL 7.0 to SQL 2000, but about the rules for
implicit conversion. Those rules have changed between SQL 7.0 and 2000. In
SQL 2000 implicit conversion is always determined by data type precedence.
In SQL 7.0 there was an exception to that rule, namely if you compare a
column with a non-column value (literal, variable, function or expression).
In that case the datatype of the column would always take precedence over
the datatype that it was compared with.
You can check the behaviour by running the example below on both versions.
On SQL 7 you should get one row returned, because the literal 11 is
converted to a VARCHAR, but on SQL 2000 the column is converted to an int,
and no row is returned:
CREATE TABLE #t (a VARCHAR(11))
INSERT INTO #t(a) VALUES (1)
INSERT INTO #t(a) VALUES (2)
SELECT a FROM #t WHERE a > 11
Jacco Schalkwijk
SQL Server MVP
"Kumar" <Kumar@.discussions.microsoft.com> wrote in message
news:A3C8EA3E-827C-4897-A23D-A11291415BD5@.microsoft.com...
>I heard that if you upgrade user database from SQL 7.0 to SQL 2000(latest
>SPs),
> there is some data type conversion precedence problem and the same query
> will produce different results on SQL 7.0 and SQL 2000.
> I am sorry, I don't have any specific examples. If someone had this
> problem,
> please advice me with some examples.
> Thanks.

No comments:

Post a Comment