Enjoy Every Sandwich

Thoughts on SQL, XML, .NET and sometimes beer.

<November 2008>
SuMoTuWeThFrSa
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456


Navigation

Tools

List O'Links

Kent's Other Stuff

Subscriptions

News

Please read these
Notices and Disclamiers

Post Categories

Article Categories



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.

posted on Friday, May 14, 2004 6:27 PM by ktegels





Powered by Dot Net Junkies, by Telligent Systems