简体   繁体   中英

How to manipulate ntext type data in stored procedure of SQL Server 2008

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM