Problem with running totals in SQL Server

  • Hi Everyone,

    I am trying to do a simple running total, but i am also doing a conversion to an int as well as a case statement.

    I am getting an error near the "AS 'RunningTotal'"

    Does anyone have any suggestions or somments on a way i can do this better or do it perioud? Thanks for the help.

    SELECT S.IssuedDateTime,

    S.ResponseId,

    Convert (int, MAX(CASE WHEN S.DisplaySequence = 1 THEN S.Response END)) AS DailyReading

    (SELECT SUM(DailyReading)

    FROM z_v_Information

    WHERE (ResponseId <= S.ResponseId)) AS 'RunningTotal'

    FROM z_v_Information S

    GROUP BY S.IssuedDateTime, S.SurveyResponseId

    Order BY S.IssuedDateTime;

  • You need a comma "," after DailyReading. Then it should at least parse.

  • try this.

    SELECT S.IssuedDateTime,

    S.ResponseId,

    Convert (int, MAX(CASE WHEN S.DisplaySequence = 1 THEN S.Response END)) AS DailyReading

    SUM(Convert (int, MAX(CASE WHEN S.DisplaySequence = 1 THEN S.Response END)))

    FROM z_v_Information

    WHERE ResponseId <= S.ResponseId

    GROUP BY S.IssuedDateTime, S.SurveyResponseId

    Order BY S.IssuedDateTime;

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply