方案1
Declare @Technic varchar(800)
Declare @CurrentIndex int
Declare @NextIndex int
Declare @TechnicCondtion varchar(1000)
Set @Technic='1,2,3,4,5,6,7,89,10,'
Set @CurrentIndex=1
print len(@Technic)
Set @CurrentIndex=CharIndex(',',@Technic)
Set @NextIndex=CharIndex(',',@Technic,@CurrentIndex+1)
-- Select @CurrentIndex,@NextIndex
-- Select Substring(@technic,@CurrentIndex+1,@NextIndex-@CurrentIndex-1)
Set @TechnicCondtion=' And Technic='+SubString(@Technic,0,@CurrentIndex)
while(@NextIndex<Len(@Technic))
Begin
Set @NextIndex=CharIndex(',',@Technic,@CurrentIndex+1)
Print @NextIndex
print @CurrentIndex
Set @TechnicCondtion=@TechnicCondtion+' And Technic='+Substring(@technic,@CurrentIndex+1,@NextIndex-@CurrentIndex-1)
Set @CurrentIndex=@NextIndex
print @TechnicCondtion
End
Select @TechnicCondtion
方案2
Set TechnicCondtion='In '+SubString(@Technic,Len(@Technic),Len(@Technic)-1)