Running Total using SQL Server with datetime

  • 18 years ago

    I am trying to create a running total on a datetime function.  I don't have a unique id? but at present I can do a count on the number of people who registered for an event in a day by using CONVERT.


    However, I want it to display a running total, rather than a count of the number of people who register per day, but I can't seem to do this.  
    Please help!!  Also the query relates to more than 1 table.
    This is an example:



    select    CONVERT(datetime,
              (CONVERT(varchar,DAY(sea.date))+'/'
              +CONVERT(varchar,MONTH(sea.date))+'/'
              +CONVERT(varchar,YEAR(sea.date))),
                              105) AS RegistrationDate
           
      , COUNT  (CONVERT(datetime,
              (CONVERT(varchar,DAY(sea.date))+'/'
              +CONVERT(varchar,MONTH(sea.date))+'/'
              +CONVERT(varchar,YEAR(sea.date))),
                              105)) As RegNos
    from    table1 sea
      INNER JOIN table2 scc ON sea.number1= scc.number5
      LEFT JOIN table3 s ON s.number2 = scc.number6
      INNER JOIN table4 con ON con.number3 = scc.number7
      LEFT JOIN table5 org ON org.number4= con.number8
    WHERE    blah = 'blah'
    AND    blah = 'blah'
    AND    blah = 'blah'
    AND    blah = 'blah'
    GROUP BY CONVERT(datetime,
              (CONVERT(varchar,DAY(sea.date))+'/'
              +CONVERT(varchar,MONTH(sea.date))+'/'
              +CONVERT(varchar,YEAR(sea.date))),
                              105))

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Computer Science is no more about computers than astronomy is about telescopes.” - E. W. Dijkstra