segue um exemplo
Create Function Uf_SplitString (@String Varchar(1000))
Returns @RetTableString Table (String Int)
As
Begin
Declare @TableString Table (String Int)
Declare @Start Int
Declare @End Int
Declare @Insert Varchar(30)
Select @Start = 1, @End = Len(@String+','), @Insert = '', @String = @String + ','
While @Start <= @End
Begin
If Substring(@String,@Start,1) = ','
Begin
Insert Into @TableString (String) Values (@Insert)
Set @Insert = ''
End
Else
Begin
Set @Insert = @Insert + Substring(@String,@Start,1)
End
Set @Start = @Start + 1
End
Insert Into @RetTableString (String) Select String From @TableString
Return
End
Create Table #Exemplo (Campo1 int)
Insert into #Exemplo (Campo1) Values (15)
Insert into #Exemplo (Campo1) Values (10)
Insert into #Exemplo (Campo1) Values (1)
Declare @StringSequencia Varchar(1000)
Set @StringSequencia = '10,20,30' -- pode ser um retorno de procedure ou passado via codigo mesmo.
Select * From #Exemplo
Inner Join (Select String From dbo.Uf_SplitString(@StringSequencia)) Tbl On Tbl.String = #Exemplo.Campo1