While loop use charindex

Here is an example of a loop using charindex

SELECT statement.

declare @site as varchar(20)
set @site = ‘1,2,3,4,5,6,7,8,9′

declare @t1 table
(
t1 int
)

while charindex(’,',@site) > 0
begin
insert into @t1 select substring(@site,1,1)
SET @site = substring(@site,3,len(@site))
end

Select * from table1
where site in ( select * from @t1)