create table #t(ID int,Content varchar(4000))
insert into #t(ID,Content)
select 1,'22,5000,3000'
union all select 2,'1,35,200,2'
union all select 3,'802,22'
union all select 4,'213,354,2002,22,500'
select * from #t
declare @sql nvarchar(4000),@i int
set @i=1
while exists(select 1 from #t where Content<>'')
begin
set @sql='alter table #t add PKQ'+convert(varchar,@i)+' int'
exec(@sql)
set @sql='declare @loc int update #t set @loc=charindex('','',Content),PKQ'
+convert(varchar,@i)+'=convert(int,case @loc when 0 then Content else '
+'substring(Content,1,@loc-1) end),Content=case @loc when 0 then '''' else '
+'substring(Content,@loc+1,len(Content)-@loc) end where Content<>'''''
exec(@sql)
set @i=@i+1
end
select * from #t
直接替换一下不就是了,用字符串函数