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
如,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
相关文章推荐
- 模拟字符串处理函数 stuff 处理 Ntext 字段
- 模拟字符串处理函数 stuff 处理 Ntext 字段
- 模拟字符串处理函数 stuff 处理 Ntext 字段
- 模拟字符串处理函数 stuff 处理 Ntext 字段
- 模拟字符串处理函数 stuff 处理 Ntext 字段
- 模拟字符串处理函数 stuff 的存储过程,对 ntext 字段进行stuff .
- 模拟字符串处理函数 stuff 处理 Ntext 字段
- 模拟字符串处理函数 stuff 处理 Ntext 字段
- 模拟字符串处理函数 stuff 处理 Ntext 字段
- 模拟字符串处理函数 stuff 的存储过程,对 ntext 字段进行stuff
- 模拟字符串处理函数 stuff 处理 Ntext 字段
- 模拟字符串处理函数 stuff 处理 Ntext 字段
- oracle字符串分割函数split
- C++的字符串分割函数的使用详解
- sql2000字符串分割
- java split()函数对字符串分割(通过空格)!
- ArcGIS字段计算器分割字段中的字符串
- JS分割字符串并放入数组的函数
- SQL语句--一个简单的字符串分割函数
- SQL Server中自定义函数:用指定的分隔符号分割字符串