title: Invalid column name error in Group By clause
body: <p>I'm trying to create a Sp for rdlc report. In which I'm using many user defined function for calculation. But when I'm trying to take function alias in group by clause it is givng an error "Msg 207, Level 16, State 1, Line 14
  Invalid column name 'CommPaid'" Below is my Query</p>
  
  <pre><code>SELECT        Employee.FirstName AS Tech, CommissionStructure.Name AS Commission, '$ ' + CONVERT(varchar(8), SUM(WorkOrderPayment.PaymentTotal)) 
                       AS TotalSales --, ISNULL(SUM(PurchaseOrder.AmountPaidToSupplier), 0) AS POAmount, ISNULL(SUM(WorkOrderPayment.TOC),0) AS TOC,
                      -- SUM(dbo.GetCashInvoiceAmount(WorkOrderPayment.WorkOrderPaymentID)) AS CashInvoice, ISNULL(SUM(dbo.GetSecTechAmount(WorkOrderPayment.WorkOrderID)),0) AS SecTechAmount
                      ,dbo.GetCommission(SUM(WorkOrderPayment.PaymentTotal),SUM(dbo.GetCashInvoiceAmount(WorkOrderPayment.WorkOrderPaymentID)),ISNULL(SUM(PurchaseOrder.AmountPaidToSupplier), 0),ISNULL(SUM(WorkOrderPayment.TOC),0),ISNULL(SUM(dbo.GetSecTechAmount(WorkOrderPayment.WorkOrderID)),0),CommissionStructure.CommissionPercentage) As CommPaid
  
  FROM            WorkOrder INNER JOIN
                       WorkOrderPayment ON WorkOrder.WorkOrderID = WorkOrderPayment.WorkOrderID INNER JOIN
                       Employee ON WorkOrder.empID = Employee.empID INNER JOIN
                       CommissionStructure ON Employee.CommissionStructureID = CommissionStructure.CommissionStructureID INNER JOIN
                       [User] ON Employee.UserID = [User].UserID LEFT OUTER JOIN
                       PurchaseOrder ON WorkOrderPayment.WorkOrderPaymentID = PurchaseOrder.WorkOrderPaymentID
  
  WHERE        (WorkOrder.OrderStatusID = 3) AND (WorkOrder.Deleted = 0) AND ([User].Active = 1) AND (CONVERT(varchar, WorkOrder.ScheduleStartTime, 101) 
                       &gt;= '10/01/2013') AND (CONVERT(varchar, WorkOrder.ScheduleStartTime, 101) &lt;= '10/24/2013')
  
  GROUP BY Employee.FirstName, CommissionStructure.Name,CommPaid
  </code></pre>
  
  <p>When I removed function alias then it give an other error which is obvious.</p>
  
  <pre><code>"Msg 8120, Level 16, State 1, Line 4
  Column 'CommissionStructure.CommissionPercentage' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."
  </code></pre>