2012-03-06 43 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

相关问题