I have a stored procedure in SQL which I can't change. It needs few input parameters and returns a table with 100+ rows and several columns.
exec dbo.Select_Data 0, 0, 18, 50
I need something to get count of returned rows:
select count(*) from (exec dbo.Select_Data 0, 0, 18, 50)
and a way to get values from e.g. Name column:
select Id, Name from (exec dbo.Select_Data 0, 0, 18, 50) where Id=10
How do I do this?
You need to create a temp table to hold the results of the stored procedure. you can then query the temp table. The schema of the temp table must match the output of the stored procedure.
Example:
CREATE TABLE #temp
(
ID INT,
NAME VARCHAR(100),
...
)
INSERT INTO #temp
Exec dbo.MyStoredProc
SELECT COUNT(*) FROM #temp
SELECT ID, NAME FROM #temp
WHERE ID = 10
DROP TABLE #temp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With