Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Running totals in return streams?
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Divers
Thread ID:
00823275
Message ID:
00823356
Vues:
13
>> Can a table returned with and SP be parsed and manipulated in this way?

Almost. While you can't directly manipulate the content of the result set, you can cache the result in a table variable, manipulate them and then return the contents of the table variable.

DELCARE @tablevar TABLE (...., runningTotal int)

INSERT INTO @tablevar (...) SELECT ...

Calculating the running total is easy. It's just the sum of the rows that come before the current row, plus the value in the current row. The hard part is identifying the row that come before the current row.
UPDATE @tablevar
SET runningTotal = value + (SELECT sum(value) FROM @tablevar t WHERE t.seq <= seq)
-Mike

>Is anyone willing to share a technique for returning a calculated value from within a stored procedure. I am using an SP to return a list of account activity but need a running balance. Can a table returned with and SP be parsed and manipulated in this way? Thanks.
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform