Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 How to derive from PROC results table?

Author  Topic 

MorningZ
Starting Member

44 Posts

Posted - 2006-09-05 : 14:32:49
Good afternoon....

Is it possible to derive a table from the results of a Stored Procedure?

For instance, i have a PROC that gets some data about out customers and I am trying to write another procedure to wrap around that PROC so i can use "GROUP BY" on those results...

So if the original procedure is called "DATA_AllData" (with params of @StartDate and @EndDate and is just a dump of all data), i want to be able to call "DATA_GroupedData" which will do something like

SELECT * FROM (
--- results from the "DATA_AllData" PROC --
) As AllData
GROUP BY [CustomerName], .. etc etc

I just cannot find the correct syntax, if it even exists, for the part inside the parentesis....

thanks in advance....

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-09-05 : 14:36:33
Insert the output from the proc into a temp table and use that in your grouping query.


CODO ERGO SUM
Go to Top of Page

nosepicker
Constraint Violating Yak Guru

366 Posts

Posted - 2006-09-05 : 17:08:32
More specifically, something like this:

CREATE TABLE #tmp_results(
col1 ...
col2 ...)

INSERT INTO #tmp_results
EXEC DATA_AllData @StartDate, @EndDate
Go to Top of Page
   

- Advertisement -