Sql语句 stuff的使用例子
declare @ids varchar(50)
declare @str1 varchar(200),@str2 varchar(200),@newStr varchar(200)
declare @i int
declare @VocationState varchar(800)
--set @VocationState=''
set @newStr=''
set @ids='11,22,33,'
set @VocationState='1,0,1,'
while @ids <>''
--while @VocationState <>''
begin
set @str1 = substring(@ids,1,charindex(',',@ids)-1)
set @str2 = substring(@VocationState,1,charindex(',',@VocationState)-1)
if(@str2='1')
set @newStr=@newStr+@str1+','
set @ids =stuff(@ids,1,charindex(',',@ids),'')
set @VocationState=stuff(@VocationState,1,charindex(',',@VocationState),'')
--select @str1,@ids
--select @str2,@VocationState
end
select @newStr=substring(@newStr,1,len(@newStr)-1)
select @newStr
浙公网安备 33010602011771号