November 30, 2007 at 10:06 am
Hello
Does anyone know if it is possible to somehow assign the COMPUTE results into local variables inside the stored procedure? The developer would like them returned as ouput parameter values (eg. @SumTotal, @AvgTotal), instead of having to deal with the second result set returned by the stored proc. I'm guessing the answer is no, but thought I'd check with the group. (Using AdventureWorks as example db)
DECLARE @sum money, @avg money
EXECUTE TestProc @sum OUT, @avg OUTPUT
CREATE PROCEDURE TestProc
@SumTotal money OUTPUT,
@AvgTotal money OUTPUT
AS
SET NOCOUNT ON
SELECT SalesOrderID, LineTotal
FROM Sales.SalesOrderDetail
COMPUTE SUM(Linetotal), AVG(Linetotal)
---
Thanks,
Joe
November 30, 2007 at 10:46 am
No,
a second query is in order
alter PROCEDURE TestProc
@SumTotal money OUTPUT,
@AvgTotal money OUTPUT
AS
SET NOCOUNT ON
SELECT @SumTotal = Sum(LineTotal), @AvgTotal = Avg(LineTotal)
FROM Sales.SalesOrderDetail
SELECT SalesOrderID, LineTotal
FROM Sales.SalesOrderDetail
November 30, 2007 at 11:47 am
Use WITH ROLLUP... search for the correct "NULLS"...
--Jeff Moden
Change is inevitable... Change for the better is not.
November 30, 2007 at 1:42 pm
I Second the ROLLUP sugesstion
In addition COMPUTE and COMPUTE BY clauses are provided for backward compatibility only.
Cheers,
* Noel
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply