0

This is really simple. Does SQL SERVER 2008 auto convert values to string for you ?

I tried this Select * from Staff Where Division = 5
If I try to insert it, it works too.
If I change 5 for five I get and error though. Invalid column name five.

Division is a NVARCHAR. Shoudn't the 5 be within single quotes ?

4

2 回答 2

0

是的,SQL Server 将 int 隐式转换为 nvarchar。它还可以将 nvarchar 隐式转换为 int (和其他数字类型)。

更多详情:http: //msdn.microsoft.com/en-us/library/ms191530.aspx

于 2012-08-03T16:01:24.273 回答
0

有很多情况会发生隐式转换。例如:

EXEC sp_who2 active;

您不需要分隔active为字符串吗?是的,但语法是宽容的。

我的建议:始终正确界定数据类型,并忽略异常。他们得到全面修复的机会几乎为零。

于 2012-08-03T16:01:51.977 回答