Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perform aggregate functions on result of stored procedure

Status
Not open for further replies.

GMcNamara

Programmer
Jun 24, 2002
235
0
0
US
I have a stored procedure that basically just does a select. Can I do aggregate functions on the procedure's result set within query analyzer without using temp tables or the actual query behind the proc?

Here is the query I tried with no luck:
select t.field1, sum(t.field2) from (
exec sp_proc1 'param1', '1/1/2008', '10/20/2008' ) t
group by t.field1
 
AFAIK - No.
But you could use table variable:
Code:
--- The rable variable should be declared with as many fields
--- as SP resultset returns, and of course with their proper
--- types
DECLARE @Test TABLE (Fld1 int, Fld2 int, Fld3 int)
INSERT INTO @Test
exec sp_proc1 'param1', '20080101', '20081020'

SELECT Fld1, SUM(Fld2)
       FROM @Test
GROUP BY Fld1

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top