我在处理sql时出错了:我不知道如何修复它:
ntext is incompatible with int
我的查询是这样的
select * from table1 where id=textfield union select name,age,(here is an ntext value) from table2
我试过使用convert(myfield as nvarchar(max)),但仍然没有将运气和错误更改为:
The ntext data type cannot be selected as DISTINCT because it is not comparable.
发布于 2014-02-08 02:24:51
第一:
不建议使用ntext,应该用nvarchar(MAX)替换它。
撇开这一点不说,ntext是不可比拟的,不能与DISTINCT或=一起使用。
当您使用关键字UNION连接2个查询时,它将自动调用一个DISTINCT操作来连接来自这两个查询的唯一数据。
但是,nvarchar(MAX)可以在DISTINCT中使用,因此,最好的解决方案是更新模型以使用这种类型而不是ntext。
如果不能这样做,则不要执行select * from table1,而是执行以下操作:
select field1, field2, Cast(field3 as NVarchar(Max))
from table1
union
select field1, field2, Cast(field3 as nvarchar(MAX))
from table2最后注:
建议在使用联合而不是*通配符时显式调用您的字段。
https://stackoverflow.com/questions/21638993
复制相似问题