set @depts = @depts + ','
while charindex(',',@depts) > 0
Begin
set @dept=left(@depts,charindex(',',@depts)-1)
insert into @DEPTTAB(deptid)
select @dept
set @depts = substring(@depts,charindex(',',@depts)+1,len(@depts) - charindex(',',@depts))
end