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
 General SQL Server Forums
 New to SQL Server Programming
 running total

Author  Topic 

rye07
Starting Member

13 Posts

Posted - 2012-03-25 : 23:36:09
as

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-03-25 : 23:43:15
why will you have records with NULL value in employeeName ? How do you know it belongs to which employee ? ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

rye07
Starting Member

13 Posts

Posted - 2012-03-26 : 00:04:47
i fix it already can u please help me how to get the running total of it :)

to god be the glory
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-03-26 : 00:28:06
[code]
; with data as
(
select *, rn = row_number() over (partition by employeeName order by orderdate)
from yourtable
)
select *
from data d
cross apply
(
select running_total = sum(orderAmount)
from data x
where x.employeeName = d.employeeName
and x.rn <= d.rn
) rt
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

rye07
Starting Member

13 Posts

Posted - 2012-03-26 : 01:15:10
thnx :)

to god be the glory
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-26 : 13:14:19
quote:
Originally posted by rye07

as


why did you delete your original question?
what help will it make to others who're trying to take something out of this thread?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-03-26 : 23:32:50
re-post over here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=172972


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -