1

我有一个表,其中有一列amounttype DEC
以下查询有效:
SELECT * FROM mytable WHERE amount < '1';

SELECT * FROM mytable WHERE amount = '1.5';

即即使我使用引号之类的amount字符值(尽管它们实际是数字),查询仍然有效。

我的问题是:
这是因为SQL Server“理解”数据类型实际上是数字并在执行sql时忽略引号select
还是
SQL Server首先将amount值转换为文本然后进行比较?所以这有一个性能转换导致的开销?

4

1 回答 1

-1

Yes there is a numerical conversion happening, since the column 'amount' is defined as numerical. To test this, you can try:

SELECT * FROM mytable WHERE amount < '1a'; 

you will get the error message:

Msg 8114, Level 16, State 5, Line 1
Error converting data type varchar to numeric.

meaning that varchar is being converted to numeric and not the other way round.

于 2013-03-30T09:54:00.873 回答