在 SQL Server 2005 中连接 ntext [英] Concatenate ntext in SQL Server 2005

查看:30
本文介绍了在 SQL Server 2005 中连接 ntext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将 2 个 ntext 列连接成一个.我无法将它们转换为 nchar,因为它们都包含长度超过 4000 个字符的字符串.有没有办法在 SQL Server 2005 中做到这一点?

I need to concatenate 2 ntext columns into one. I can't convert them to nchar, cause both contains strings longer than 4000 chars. Is there a way to do this in SQL Server 2005?

推荐答案

UPDATE 
    YourTable
SET 
    Field = CAST( (CAST(field1 AS NVARCHAR(MAX)) + CAST(field2 AS NVARCHAR(MAX))) AS NTEXT)
WHERE 
    (your condition here)

但实际上 - 在 SQL Server 2005 中,NTEXT 已被弃用,并且很可能会在 SQL Server 2008 R2 或更高版本中逐步淘汰.NVARCHAR(MAX) 是逻辑上的继承者,给你所有的 NTEXT 给你,还有更多!

But really - with SQL Server 2005, NTEXT becomes deprecated and will most likely be phased out in SQL Server 2008 R2 or one release later. NVARCHAR(MAX) is the logical successor, giving you all NTEXT ever gave you, and a lot more!

如果您的字段从一开始就是 NVARCHAR(MAX),您可以只写:

If your fields would be NVARCHAR(MAX) from the beginning, you could just write:

UPDATE 
    YourTable
SET 
    field = field1 + field2
WHERE 
    (your condition here)

并完成它!

我建议您升级您的表格以使用 NVARCHAR(MAX) 而不是 NTEXT.

I'd suggest you upgrade your tables to use NVARCHAR(MAX) instead of NTEXT.

马克

这篇关于在 SQL Server 2005 中连接 ntext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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