SQL Server 2008的存储过程中如何操作ntext类型的数据

问题描述:

我想知道如何在 SQL Server 2008 的存储过程中操作 ntext 数据类型.我们在表中有一个 ntext 类型的列.我们必须从该列中获取数据,解析数据,更改然后将其存储回来.对于上述所有任务,我们必须使用一个或多个存储过程/函数.所以也涉及到存储过程之间的数据传递.

I was wondering how to manipulate ntext datatype in stored procedure of SQL Server 2008. We have a column of type ntext in a table. We have to fetch data from that column, parse the data, change and then store it back. For all of the above task we have to use one or more than on stored procedure/function. So data passing between stored procedures are also involved.

如果您可以更改架构,请考虑将数据类型从 ntext 更改为 nvarchar(max).后者是 SQL Server 2005 中的新增功能,效率更高,并且可以与字符串函数一起使用.

If you're in the position to change the schema, consider changing the data type from ntext to nvarchar(max). The later is new in SQL Server 2005, it's more efficient, and it works with string functions.

如果您无法更改架构,请将 ntext 转换为 nvarchar(max) 类型的局部变量.字符串函数与 nvarchar(max) 一起工作.示例:

If you can't change the schema, convert the ntext to a local variable of type nvarchar(max). String functions do work with nvarchar(max). Example:

declare @txt nvarchar(max)
select @txt = NTextField from YourTable where id = @ID

... process @txt ...

update YourTable set NTextField = @txt where id = @ID