li.的博客
|
create function dbo.fn_split
(
@inputstr varchar(8000),
@seprator varchar(10)
)
returns @temp table (a varchar(200))
as
begin
declare @i int
set @inputstr = rtrim(ltrim(@inputstr))
set @i = charindex(@seprator, @inputstr)
while @i >= 1
begin
insert @temp values(left(@inputstr, @i - 1))
set @inputstr = substring(@inputstr, @i + 1, len(@inputstr) - @i)
set @i = charindex(@seprator, @inputstr)
end
if @inputstr <> '\'
insert @temp values(@inputstr)
return
end
go
select * from dbo.fn_split(‘10、20、30’,'、')
declare cursor_insert cursor for select col1 from [stable1]
declare @i nvarchar(200)
open cursor_insert
fetch cursor_insert into @i
while @@fetch_status=0
begin
--print @i
insert into [table1]
select * from dbo.fn_split(@i,'、')
fetch cursor_insert into @i
end
close cursor_insert
deallocate cursor_insert