question

ronbarlow-5250 avatar image
0 Votes"
ronbarlow-5250 asked EchoLiu-msft commented

Count Records in Stored procedure without returning rows

Hello

I've got a stored procedure that returns a data set. The procedure is made up of dynamic sql including a number of dynamic CTE's

What I need to do is count the rows returned in the procedure without returning the rows. Reason being that if the are now row another procedure is called. Is there a straight forward way to do this?

Any suggestion welcome
Ron

sql-server-transact-sql
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ErlandSommarskog avatar image
0 Votes"
ErlandSommarskog answered EchoLiu-msft commented

You would have to insert the rows you produce in a temp table or a table variable, and then check @@rowcount after the insertion operation to see how many rows that were inserted.

Beware that @@rowcount is updated for every operation, so save it to a local variable immediately.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks Erland

0 Votes 0 ·

I am glad that your problem has been resolved, if you have any questions, welcome to the Q&A forum!

Regards
Echo

0 Votes 0 ·