有没有办法在 SQL Server 2005 中按文本(或 ntext)进行 DISTINCT 或分组? [英] Is there any way to DISTINCT or group by a text (or ntext) in SQL Server 2005?

查看:32
本文介绍了有没有办法在 SQL Server 2005 中按文本(或 ntext)进行 DISTINCT 或分组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个表中,我有一个名为 MEMO_TEXT 的列,它是一种文本数据类型.当我尝试创建视图并使用 GROUP BY 时,出现以下错误:

In a table, I have a column called MEMO_TEXT that is a text data type. When I try creating a view and use a GROUP BY, I get the following error:

SQL Server 数据库错误:无法比较或排序 text、ntext 和 image 数据类型,除非使用 IS NULL 或 LIKE 运算符.

SQL Server Database Error: The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.

当我尝试对查询执行 DISTINCT 时,我也收到此错误.关于如何解决这个问题的任何想法?

I get this error when I try to do a DISTINCT on the query as well. Any ideas on how to get around this?

如果您需要更多信息,请告诉我.

If you need any more information, please let me know.

推荐答案

围绕它的一个技巧是将其转换为 nvarchar(max).

One hack around it is to cast it as an nvarchar(max).

这是一种将字符串长度增加到 4,000 以上的记录方法:

This is a documented way to increase the string length beyond 4,000:

nvarchar [ ( n | max ) ]

可变长度的 Unicode 字符串数据.n 定义字符串长度,可以是 1 到 4,000 之间的值.ma​​x 表示最大存储大小为 2^31-1 字节(2 GB). 存储大小(以字节为单位)为实际输入数据长度的两倍 + 2 个字节.nvarchar 的 ISO 同义词是 national char variables 和 national character changed.

Variable-length Unicode string data. n defines the string length and can be a value from 1 through 4,000. max indicates that the maximum storage size is 2^31-1 bytes (2 GB). The storage size, in bytes, is two times the actual length of data entered + 2 bytes. The ISO synonyms for nvarchar are national char varying and national character varying.

类似的技巧适用于 varchar().

这篇关于有没有办法在 SQL Server 2005 中按文本(或 ntext)进行 DISTINCT 或分组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆