用sql 将字符串进行处理 原字符串为123,2,256,2,333,3, 变成 123,123,256,256,333,333,333,形式
sql为:
Declare @S1 varchar(max) Select @S1='123,2,256,2,333,3, ' declare @d1 varchar(max) set @d1='' declare @n int set @n=0; declare @s3 varchar(max) --while CHARINDEX(',',@S1)=0 while LEN(@S1)>0 begin set @s3=(Select Substring(@S1,0,PATINDEX('%,%',@S1)))--123 --print @s3; set @S1= (Select Substring(@S1,PATINDEX('%,%',@S1)+1,Len(@S1)))--剩余长度 --print @S1; set @n=(Select Substring(@S1,0,PATINDEX('%,%',@S1)))--第二个数 if @n=1 set @d1=@d1+@s3+',' else while @n>=1 begin set @d1=@d1+@s3+',' set @n=@n-1 end set @S1= (Select Substring(@S1,PATINDEX('%,%',@S1)+1,Len(@S1)))--剩余长度 --print @S1; end print @d1
转载请注明原文地址: https://ju.6miu.com/read-969000.html