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.
Author |
Topic |
JohnMcLaughlin
Starting Member
28 Posts |
Posted - 2010-11-10 : 09:31:57
|
The table i have looks like thisCol1 Date Type Money Money2A 1/1/10 Z 0.75 0.75A 2/1/10 X 0.03 0.78A 3/1/10 X 0.01 0.79A 4/1/10 X 0.02 0.81B 1/1/10 Z 0.61 0.61B 2/1/10 X 0.01 0.62B 3/1/10 X 0.04 0.66B 4/1/10 X 0.02 0.83This is quite hard to explain in words but i will try. Eventually i want the Money column to look like Money2. On each date there is a different money value which adds to the base value (shown as type z). So for the next date i would like the value to be added to the previous dates value. Any help would be much appreciated. |
|
Sachin.Nand
2937 Posts |
|
JohnMcLaughlin
Starting Member
28 Posts |
Posted - 2010-11-10 : 10:17:43
|
I am trying to do the running total but it is totalling the whole column. This is the SQL i have tried. SELECT TOP (100) PERCENT Col1, CONVERT(char(10), Date, 101) AS 'Date', Money, (SELECT SUM(Money) AS Expr1 FROM dbo.[NAS_Inv fees]) AS 'Running Total'FROM dbo.[NAS_Inv fees] AS [NAS_Inv fees_1]ORDER BY col1How can i get it to do a running total for each letter in col1. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-11-10 : 10:44:03
|
[code]SELECT TOP (100) PERCENT Col1, CONVERT(char(10), Date, 101) AS 'Date', Money,r.[Running Total]FROM dbo.[NAS_Inv fees] AS [NAS_Inv fees_1]CROSS APPLY(SELECT SUM(Money) AS [Running Total]FROM dbo.[NAS_Inv fees]WHERE Col1 = [NAS_Inv fees_1].Col1AND Date <= [NAS_Inv fees_1].Date )r ORDER BY col1[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|