简体   繁体   English

ntext与int MSSQL Server不兼容

[英]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.

相关问题 SQL Server 错误 - 操作数类型冲突:ntext 与 int 不兼容 -(我什至没有使用“ntext”) - SQL Server error - Operand type clash: ntext is incompatible with int - (I'm not even using "ntext") MS SQL Server NTEXT到INT - MS SQL Server NTEXT to INT SQL Server 2005:插入查询返回操作数类型冲突:ntext与smallint不兼容 - SQL Server 2005: Insert query returning Operand type clash: ntext is incompatible with smallint 将mssql中的xml ntext转换为CSV(ucomponents迁移) - Convert xml ntext in mssql to csv (ucomponents migration) SubmitChanges上的错误“数据类型ntext和nvarchar不兼容” - error “data types ntext and nvarchar are incompatible” on SubmitChanges 在SQL Server 2005中连接ntext - Concatenate ntext in SQL Server 2005 SQL 服务器错误“操作数类型冲突:varchar 与 int 不兼容” - SQL Server error "Operand type clash: varchar is incompatible with int " SQL 服务器“操作数类型冲突:int 与日期不兼容”错误 - SQL Server 'Operand type clash: int is incompatible with date' error 获取“数据类型nvarchar(max)和ntext在等于运算符中不兼容”。 - Getting a 'The data types nvarchar(max) and ntext are incompatible in the equal to operator.' SQL Server Operand类型冲突:日期与int不兼容 - Sql Server Operand type clash: date is incompatible with int
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM