• You have some errors on the way you want to generate the query. You can't combine the assignment of variables with the return of results and you need to write a CASE for each column on your query (at least).

    However, I don't understand why would you want to count a value returned by a formula. Wouldn't you need to use SUM?

    Here's my interpretation from your query. I have nothing to test and I don't know what you expect from this. For better answers, please read the article linked in my signature.

    ALTER PROCEDURE DoubleSidedSheets @StartDate DATETIME,

    @EndDate DATETIME,

    @SCount INT = 0,

    @DCount INT = 0,

    @DSheets INT = 0,

    @SSheets INT = 0

    AS

    SELECT Right(rpt.[Cost Center], 4) AS [Cost Center Name],

    rpt.[User Id] AS [User ID],

    CASE

    WHEN rpt.Pages = rpt.[Sheets]

    THEN @SCount + rpt.[Sheets]

    ELSE @SCount + (Sheets - (Pages / 2))

    END AS [Single Sided Print],

    CASE

    WHEN rpt.Pages = rpt.[Sheets]

    THEN @DCount = 0

    ELSE (Pages / 2) + @DCount

    END AS [Double Sided Print]

    FROM rpt_print_transactions rpt

    WHERE rpt.[Date/Time] >= @StartDate

    AND rpt.[Date/Time] <= @EndDate

    GROUP BY rpt.[Cost Center],

    rpt.[User Id]

    GO

    ---OR

    ALTER PROCEDURE DoubleSidedSheets @StartDate DATETIME,

    @EndDate DATETIME,

    @SCount INT = 0,

    @DCount INT = 0,

    @DSheets INT = 0,

    @SSheets INT = 0

    AS

    SELECT Right(rpt.[Cost Center], 4) AS [Cost Center Name],

    rpt.[User Id] AS [User ID],

    SUM(CASE

    WHEN rpt.Pages = rpt.[Sheets]

    THEN @SCount + rpt.[Sheets]

    ELSE @SCount + (Sheets - (Pages / 2))

    END) AS [Single Sided Print],

    SUM(CASE

    WHEN rpt.Pages = rpt.[Sheets]

    THEN @DCount = 0

    ELSE (Pages / 2) + @DCount

    END) AS [Double Sided Print]

    FROM rpt_print_transactions rpt

    WHERE rpt.[Date/Time] >= @StartDate

    AND rpt.[Date/Time] <= @EndDate

    GROUP BY rpt.[Cost Center],

    rpt.[User Id]

    GO

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2