[英]ntext is incompatible with int MSSQL Server
I was working on sql when I got error: I don't know how to fix it: 出现错误时,我正在使用sql:我不知道如何解决它:
ntext is incompatible with int
my query is like this 我的查询是这样的
select * from table1 where id=textfield union select name,age,(here is an ntext value) from table2
I tried using convert(myfield as nvarchar(max))
but still no luck and error changed to this: 我尝试使用
convert(myfield as nvarchar(max))
但仍然没有运气,并且错误更改为:
The ntext data type cannot be selected as DISTINCT because it is not comparable.
First : 首先:
ntext
is deprecated and should be replaced with nvarchar(MAX)
. 不推荐使用
ntext
,应将其替换为nvarchar(MAX)
。
That aside, ntext
is not comparable and can't be used with DISTINCT
or =
. 除此之外,
ntext
不可比,并且不能与DISTINCT
或=
一起使用。
When you use the key word UNION
to join 2 queries it will automatically call a DISTINCT
operation to join only unique data from both queries. 当您使用关键字
UNION
2个查询时,它将自动调用DISTINCT
操作以仅联接来自两个查询的唯一数据。
However, nvarchar(MAX)
can be used within a DISTINCT
thus, the best solution is to update your model to use this type instead of ntext
. 但是,可以在
DISTINCT
使用nvarchar(MAX)
因此,最好的解决方案是更新模型以使用此类型而不是ntext
。
If this can't be done, instead of doing select * from table1
go with : 如果无法做到这一点,请代替
select * from table1
,而select * from table1
:
select field1, field2, Cast(field3 as NVarchar(Max))
from table1
union
select field1, field2, Cast(field3 as nvarchar(MAX))
from table2
Last note : 最后说明:
It is recommended to call your fields explicitly when using a union instead of the *
wildcard. 建议在使用联合而不是
*
通配符时显式调用您的字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.