2012-03-06 54 views
0

我試圖弄清楚如何在分組時使用select分支中的列別名。我有我的查詢工作。唯一的問題是AccountsDescription是實際的列名,我需要結果集來使用別名Account。有人能指引我朝着正確的方向嗎?如何在分組時使用Select Case中的列別名

Select 
    Case 
     When GROUPING (AccountDescription) = 1 then '*ALL*' 
     Else AccountDescription 
    End As AccountDescription, 
     Vendors.VendorState As State, 
     Sum(InvoiceLineItems.InvoiceLineItemAmount) as LineItemSum 
From 
    InvoiceLineItems Join GLAccounts On 
    InvoiceLineItems.AccountNo = GLAccounts.AccountNo 
    Join Invoices On 
    InvoiceLineItems.InvoiceID = Invoices.InvoiceID 
    Join Vendors On 
    Invoices.VendorID = Vendors.VendorID 
Group by GLAccounts.AccountDescription, Vendors.VendorState with Cube 
+0

我有一個+1給你,如果你選擇約翰皮克的答案作爲正確的答案... – ONDEV 2013-04-26 15:10:39

回答

2

如果你寫As AccountDescription,將其更改爲As Account

+0

好吧,現在我覺得自己像個白癡!我無法告訴你我浪費了多少時間來忽略這些顯而易見的事情。感謝您挖掘我! – 2012-03-06 08:23:04