字串资料转成如表a
请教如何将以下的字串资料转成如表a
111,222,333,444,555
表a:
111
222
333
444
555
------解决方案--------------------create table #t(str varchar(20))
go
declare @sql varchar(2000)
declare @str varchar(200)
set @str= '111,222,333,444,555 '
set @str=replace(@str, ', ', ' union select ')
set @sql= 'insert into #t select '+@str
print @sql
exec(@sql)
select * from #t
drop table #t
-----------------------
str
-----------------------
111
222
333
------------------------
insert into #t select 111 union select 222 union select 333 union select 444 union select 555
(5 行受影响)
(5 行受影响)
444
555