Creating a stored procedure to return a row string of another stored procedure

Can this be done? I have some filters installed in my original stored procedure, and I really don't want to duplicate it in another to get the line number.

+4
source share
3 answers

The only way I know how to do this is to insert into the temporary table from the stored procedure, and then select the counter. Unfortunately, there is no proper way to make a "selection" in a stored procedure.

CREATE TABLE #stuff (id int, status char(6)) INSERT #stuff (id, status) EXEC dbo.sp_get_stuff SELECT count(*) FROM #stuff DROP TABLE #stuff 

Edit

The above method will allow you to choose from a stored procedure, but as Greg pointed out, the string value can be simplified to:

 EXEC dbo.sp_get_stuff SELECT @@Rowcount 
+6
source

This also works:

 create proc pTest1 as select * from comp go create proc pTest2 as exec pTest1 select @@rowcount GO 
+3
source

If you are really trying to tune the melody as much as possible, you will have to change the original stored procedure. If you are looking at performance, then returning a rowset just to get the score is not worth considering.

+1
source

All Articles