当前位置: 移动技术网 > IT编程>数据库>MSSQL > SqlServer 2005 中字符函数的应用

SqlServer 2005 中字符函数的应用

2017年12月08日  | 移动技术网IT编程  | 我要评论

龙将顾问战国游,中兴r518游戏,太罗奥特全集

复制代码 代码如下:

use demo
go
/*
将表code的列string中的值提取放到record表中
string 中字符类型为
dsddddd,2222222,222221,3
其中最后一位为标记对于record表中的biaoji
前面的以','分割的是值对应record表中value
*/
go
drop proc proc_split_code
go
create proc proc_split_code
as
begin
set nocount on

declare @count int --条数
declare @index int --变量
set @index = 1 --默认
select @count = count(*) from code
--print @count
while (@index<=@count)
begin
declare @biaoji int -- 标记
declare @string nvarchar(1000)--字符串
declare @temp int --分隔符的位置
declare @star int --开始位置
declare @code nvarchar(100) --
set @star = 0
select @string=reverse(string)
from (
select row_number() over(order by string) as rownumber,* from code
) as a
where rownumber between @index and @index

set @temp=charindex(',',@string,@star)
set @biaoji = substring(@string,@star,@temp)
print @biaoji
set @string = reverse(@string)
set @temp=charindex(',',@string,@star)
set @star = 0
while(@temp>0)
begin

set @temp=charindex(',',@string,@star)

--print @star
--print @temp

if @temp >0
begin
set @code=substring(@string,@star,@temp-@star)
print @code
--插入到相应的表中
insert into record(biaoji,value,time)
values (@biaoji,@code,getdate())

end
set @star=@temp+1
end

--print @index
print @string
set @index = @index+1
end
end
go

exec proc_split_code

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网