Go into QUERY ANALYZER and copy this into a query window...
So what you see with this example is that you can take a STRING of comma-separated values and put them into a TABLE VARIABLE (or a TEMPORARY TABLE if desire).
Set NoCount On
Declare @ListStr varchar(100)
Declare @ListTbl Table (SelectValue int)
Declare @CP int
Declare @SV int
Set @SV=Cast(Left(@ListStr,@CP-1) as int)
Set @SV=Cast(@ListStr as int)
Insert into @ListTbl Values (@SV)
Select * From @ListTbl
Then you do your query like this:
Select * From SomeTable Where Id in (Select SelectValue From @ListTbl)
Select * From @ListTbl LT
Left Join SomeTable ST on ST.Id=LT.SelectValue
or I'm sure several other variations would work as well...