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

posted on 2008-09-24 16:31  念时  阅读(632)  评论(0)    收藏  举报

细节决定成败!态度决定一切!