SQL 101: record count for a procedure
While I'm not on Skype, sometimes folks will IM me with questions. Just got done with one from Daniel in Germany.
Question How do you get the number of records that a stored procedure would return without actually returning the result set to the user?
Answer Answer: Cheat!
Consider the following meager stored procedure:
alter procedure dbo.GetBeers
as
select BeerID from dbo.Beers
Here's the cheating bit. I'm actually going to execute that procedure and have the results pumped into a temporary table, which we can then query for the count.
create table #beercount
(beerid int)
insert into #beercount exec dbo.getbeers
select count(*) from #beers
drop #beercount
Brown Rice is, indeed, Ok.