首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

字串资料转成如表a,该如何处理

2012-03-16 
字串资料转成如表a请教如何将以下的字串资料转成如表a111,222,333,444,555表a:111222333444555[解决办法]c

字串资料转成如表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

热点排行