I think creating and executing a dynamic SQL statement would not add much overhead. However, I do have a solution that doesn't require an EXEC.
-- Set nocount on to inhibit
-- rows affected messages
set nocount on
-- Assume the variable @status is
-- declared in the SP definition
If Len(@status)=0
Begin
Print 'No input'
Return
End
-- Decalre additional variables for
-- proecedure that follows
Declare @p1 int, @p2 int, @s int
-- Create a temporary to hold the
-- values parsed from @status
Create table #t1 (Stat int)
-- Initialize character position variables
Set @p1=1
-- Find first comma
Set @p2=charindex(',',@status,@p1)
-- Parse @status and insert values into #t1
If @p2=0
-- Handle case of single value
Set @s=cast(@status As Int)
Else
Begin
While @p2>0
Begin
-- get integer value from list
Set @s=cast(substring(@status,@p1,@p2-@p1) As Int)
-- Insert integer into table
Insert #t1 Values (@s)
-- Increment variable
Set @p1=@p2+1
-- Find next comma
Set @p2=charindex(',',@status,@p1)
End
-- Handle last value in list
Set @s=cast(right(@status,len(@status)-@p1+1) As Int)
-- Insert last value in table
Insert #t1 Values (@s)
End
-- Select values from permanent table
-- that exist in the temporary table.
Select * From tblTable
Where Status In (Select stat From #t1)
Let me know if you have any questions. Terry L. Broadbent
Programming and Computing Resources