CREATE TABLE #Cate(CateId int) declare @s nvarchar(1000) set @s='12|55|77|99|121' while charindex('|',@s)>0 begin insert #Cate select left(@s,charindex('|',@s)-1) set @s=stuff(@s,charindex('|',@s)) end insert #Cate select @s -------结果 select * from #Cate
CREATE TABLE #tmp1(CateId int) declare @s nvarchar(1000) set @s='12|55|77|99|121' while charindex('|',@s)>0 begin insert #tmp1 select left(@s,charindex('|',@s)-1) set @s=stuff(@s,1,charindex('|',@s),'') end insert #tmp1 select @s -------结果 select * from #tmp1 drop table #tmp1
declare @s nvarchar(1000)
set @s='12|55|77|99|121'
while charindex('|',@s)>0
begin
insert #Cate select left(@s,charindex('|',@s)-1)
set @s=stuff(@s,charindex('|',@s))
end
insert #Cate select @s
-------结果
select * from #Cate
declare @s nvarchar(1000)
set @s='12|55|77|99|121'
while charindex('|',@s)>0
begin
insert #tmp1 select left(@s,charindex('|',@s)-1)
set @s=stuff(@s,1,charindex('|',@s),'')
end
insert #tmp1 select @s
-------结果
select * from #tmp1
drop table #tmp1