Sum() function with gridview RRS feed

  • Question

  • User1622691836 posted

    I have a sum function and not sure if this should work or not. Here is my code.

    <asp:AccessDataSource ID="AccessDataSource3" runat="server" DataFile="~/App_Data/SalesEntry.accdb" 
           SelectCommand="SELECT [Sales.EmployeeName], [Sales.Company], SUM([Sales.ExtendedPrice] WHERE [Sales.Company] = 'NSI Renewals') AS NSIRtotalFinal),
                                (SUM([Sales.ExtendedPrice]) AS ExtendedPriceTotal) FROM [Sales] Group By EmployeeName, Company">

    The one that I am most concerned about is the first Sum() function. This is the error that I am getting.

    Syntax error (missing operator) in query expression 'SUM([Sales.ExtendedPrice] WHERE [Sales.Company] = 'NSI Renewals')'

    Monday, September 30, 2013 4:14 PM


  • User-1716253493 posted

    Try this

    SUM(IIF([Sales.Company] = 'NSI Renewals',[Sales.ExtendedPrice],0)) AS NSIRtotalFinal,
    SUM(IIF([Sales.Company] = 'NSI Renewals',0,[Sales.ExtendedPrice])) AS ExtendedPriceTotal

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 30, 2013 11:56 PM