您的位置:首页 > 数据库

sql2000中ntext字段字符串分割函数

2008-11-20 23:37 519 查看
将ntext字段按照指定字符串分割成数据表

如,ntext字读,

11111111111111111111111111\n

22222222222222222222222222\n

33333333333333333333333333\n

转换为:

1,11111111111111111111111111

2,22222222222222222222222222

3,33333333333333333333333333

create  function [dbo].[StrSplit2](@tableID uniqueidentifier,@splitSign nvarchar(10))

returns @table table (itemid int identity(1,1),tempStr nvarchar(1000))
as

begin

  declare   @s   nvarchar(4000),@i   int,@j   int  
  select   @s=substring(Data,1,4000),@i=1  
from tj_data1 
where tableid=@tableID

  while   @s<>'' 
 
 begin  
if   len(@s)=4000  
 select   @j=4000-charindex('n\',reverse(@s))  
 ,@i=@i+@j+1
 ,@s=left(@s,@j-1)  
  else    
 select   @i=@i+4000,@j=len(@s) 

while charindex(@splitSign,@s)>0
begin
insert into @table (tempStr)
select left(@s,charindex(@splitSign,@s)-1)

select @s=stuff(@s,1,charindex(@splitSign,@s)+len(@splitSign)-1,'')

end
insert @table (tempStr) select @s

 select   @s=substring(Data,@i,4000) 
from tj_data1 
where tableid=@tableID
 end  

return
end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: