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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MalcolmW - re: FAQ 183-207 1

Status
Not open for further replies.

redlam

MIS
Jun 28, 2000
218
US
Malcolm - are you out there?
I was hoping you could help me with running totals. I read your FAQ but couldn't seem to make it meet my needs. I'm either completely missing the boat (entirely possible X-) ) or maybe it just can't be done the way I'm trying to use it. Is it possible to return a running total in a select statement like this (without cursors or temp tables):

select unique_id,
numeric_value,
<running total of numeric value>
from test_table

Thanks for your help.
 
Here is some sample code that may be of interest - sounds like it is not of use at this point. In this sample, a running total is being made of a field that includes null values, which adds to the complexity slightly. Theoretically sums of fields containing nulls shouldn't be a common occurance.
create table #titles (title_id varchar(10), price decimal(9,2), RTPrice decimal(9,2))
insert into #titles select title_id, Price, case when Price is null then 0 else Price end as RTPrice from titles
declare @variable decimal(9,2)
set @variable = 0
update #titles
SET @variable = RTPrice = @variable + RTPrice
select * from #titles Malcolm Wynden
Authorized Crystal Engineer
malcolm@wynden.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top