首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

数据类型 ntext 跟 varchar 在 equal to 运算符中不兼容

2013-12-13 
数据类型 ntext 和 varchar 在 equal to 运算符中不兼容在运用SQL Server时,出现了一些问题,请各位帮小弟

数据类型 ntext 和 varchar 在 equal to 运算符中不兼容
在运用SQL Server时,出现了一些问题,请各位帮小弟一下;
首先,我的数据库student,有一个表student1,数据类型 ntext 跟 varchar 在 equal to 运算符中不兼容
在表中插入了两条记录:123456,小王;123457,小明
在进行查询操作时,select * from student1 where Name = '小王',出现:数据类型 ntext 和 varchar 在 equal to 运算符中不兼容的错误,我按照网上寻找的3种解决办法重新做,
1:select * from student1 where Name like '小王'
2:select * from student1 where convert(nvarchar(500),Name) = '小王'
3:select * from student1 where cast(Name as nvarchar(500))='小王'
奇怪的是,这三种方法均查询不到相匹配的记录结果,数据类型 ntext 跟 varchar 在 equal to 运算符中不兼容

请问各位,这要怎么解决,
[解决办法]
试试:
1:select * from student1 where Name like N'小王'
2:select * from student1 where convert(nvarchar(500),Name) = N'小王'
3:select * from student1 where cast(Name as nvarchar(500))=N'小王'
[解决办法]
处理 Unicode 字符串常数中 SQL Server 时您必须在前面所有的 Unicode 字符串以大写的字母 N,SQL Server 联机丛书主题使用 Unicode 数据中所述。"N"前缀代表在 sql-92 标准国家语言,而且必须为大写。如果您不执行前缀 Unicode 字符串常量,用 N,SQL Server 会将其转换为当前数据库的非 Unicode 代码页之前它将使用该字符串。

热点排行