Friday 2 October 2009

Querying the results of a stored procedure

If you want to run a query against the results of a stored procedure a simple solution is to use a temporary table and the “INSERT INTO” SQL syntax. For example:

CREATE TABLE #MyTempTable (
     some_field varchar(10),
     some_other_field varchar(40)
)

INTERT INTO #MyTempTable
     EXEC my_stored_procedure

SELECT * FROM #MyTempTable WHERE some_field LIKE '%some value%'
    
DROP TABLE #MyTempTable
GO