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

落花浮王杯 提交于 2019-12-13 14:08:25

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/8507047/how-to-manipulate-ntext-type-data-in-stored-procedure-of-sql-server-2008

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!