ntext 数据的 GROUP BY [英] GROUP BY for ntext data

查看:31
本文介绍了ntext 数据的 GROUP BY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想看看 MSGTEXT 在表 MMOUTBOUND 中重复了多少次.为此,我使用以下查询:

I would like to see how many times the field MSGTEXT is repeated in the table MMOUTBOUND. For that I use the following query:

SELECT 
    MSGTEXT, 
    COUNT(*) TotalCount 
FROM MMOUTBOUND 
GROUP BY MSGTEXT 
HAVING COUNT(*)>1;

但我收到一个错误,因为无法比较或排序 ntext 数据类型.我如何为 ntext 数据类型实现这一点?

But I get an error because ntext data types cannot be compared or sorted. How can I achieve this for the ntext data type?

推荐答案

你不能直接针对整列.但是,您可以间接地转换前 N 个字符和分组,例如

You can't directly, for the entire column. However, indirectly, you can convert the first N characters and group by this instead, e.g.

SELECT CONVERT(NVARCHAR(100), MSGTEXT), COUNT(*) TotalCount 
FROM MMOUTBOUND 
GROUP BY CONVERT(NVARCHAR(100), MSGTEXT) 
HAVING COUNT(*)>1;

正如其他人所指出的,请注意您应该将 NTEXT 列转换为 NVARCHAR(MAX)

As others have noted, note that you should convert your NTEXT columns to NVARCHAR(MAX)

这篇关于ntext 数据的 GROUP BY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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