title: Incorrect syntax near the keyword 'AS', trying to find sum
body: <p>I checked the other questions similar to the title and could not find the answer. I am working through a software, so I unable to tweak the SQL directly, I can only change certain parts. </p>
  
  <blockquote>
    <p>[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near the keyword 'AS'.</p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre><code>SET NOCOUNT ON; 
  DECLARE @ShowZeros nVarChar(4000);
  
  SET @ShowZeros  = 'N';
  
  SELECT 
      IC_ProductLots.Available_Alt
      , IC_Products.UnitOfMeasure_Alt
      , IC_ProductLots.Available_Stk
      , IC_Products.UnitOfMeasure_Stk
      , IC_Products.Description1
      , IC_Products.ProductCode
      , AR_Customers.CustomerCode
      , AR_Customers.Name
      , SUM([IC_ProductLots].[Available_Stk]) GROUP BY [AR_Customers].[CustomerCode] AS [Total Stock]
  FROM ((( DC_Transactions 
      INNER JOIN  AR_Customers 
          ON DC_Transactions.CustomerKey = AR_Customers.CustomerKey)
      INNER JOIN  IC_ProductLots 
          ON DC_Transactions.LotKey = IC_ProductLots.LotKey)
      INNER JOIN  IC_Products 
          ON DC_Transactions.ProductKey = IC_Products.ProductKey)
  WHERE 
      (IC_Products.ProductCode = '      515070')  
      AND (
          (
              CASE 
                  WHEN @ShowZeros = 'Y' or @ShowZeros = 'YES' THEN 1 
                  ELSE (ISNULL([IC_ProductLots].[Available_Stk],0))
              END
          ) &gt; 0
      )
  ORDER BY 
      IC_Products.ProductCode 
    , AR_Customers.CustomerCode 
    , AR_Customers.Name
  </code></pre>
  
  <p>I am trying to find the sum of the Available stock, how ever I run into a problem with my Select sum statement:</p>
  
  <pre><code> SUM([IC_ProductLots].[Available_Stk]) 
   GROUP BY [AR_Customers].[CustomerCode] AS [Total Stock]
  </code></pre>
  
  <p>The answer was found but my output is still not correct, 
  It should appear as this:
  Output should look similar to below:</p>
  
  <pre><code>Cases | U/M  | Total Stock | Description | Cust Name  | Cust Code
  -----------------------------------------------------------------
  57    | CS   | 1779.45     | Food        | Restaurant | 2
  4     | CS   | 120         | Dough       | Bakery     | 44
  </code></pre>
  
  <p>Currently it prints out 57 lines for customer code 2 and 4 lines for customer code 44, displaying the same information for each customer code. Basically it prints out a line for every case that customer has.</p>