I have this table DDL:
CREATE TABLE [dbo].[Audit] (
[AuditId] INT IDENTITY (1, 1) NOT NULL,
[Entity] INT NOT NULL,
[Action] INT NOT NULL,
[Id] UNIQUEIDENTIFIER NULL,
CONSTRAINT [PK_Audit] PRIMARY KEY CLUSTERED ([AuditId] ASC)
);
Update - I added the missing SQL here. Sorry about that
What I did was create a SQL report using this SQL that would show me how much activity there was each day:
select [col1] = CONVERT(VARCHAR(10), DATEADD(HOUR, 8, a.date), 101) ,
[Col2] = convert(varchar, count(*))
from Audit a
group by CONVERT(VARCHAR(10), DATEADD(HOUR, 8, a.date), 101)
order by CONVERT(VARCHAR(10), DATEADD(HOUR, 8, a.date), 101) desc
The output looks like this:
col1 Col2
03/05/2017 1
03/04/2017 20
03/03/2017 10
03/02/2017 5
03/01/2017 10
What I now need to do is to create a SQL select that shows me a cumulative value and not the count. So I need SQL that clould create a report that would show this
col1 Col2
03/05/2017 46
03/04/2017 45
03/03/2017 25
03/02/2017 15
03/01/2017 10
Does anyone have any idea as to how I can modify my SQL to create this type of a report?
Note that I am really looking for a one command solution as it is executed from .net framework and if there are multiple commands in the solution I think I would need to work out how to put this into a stored procedure somehow.