SQL Server 中查询text数据类型报错, The data types text and varchar are incompatible in the equal to operator.

SQL Server 执行普通查询语句

SELECT * FROM [Details] WHERE [Content]='1'

如果Content字段是text类型,则会弹出以下错误

The data types text and varchar are incompatible in the equal to operator.


解决办法:

text类型不能直接进行查询操作,需要进行转换

SELECT * FROM [Details] WHERE CAST([Content] AS [nvarchar](2000))='1';


热门推荐