如何在分组时选择案例中使用列别名

时间:2012-03-06 07:43:29

标签: sql-server

我试图弄清楚在分组时如何在select case中使用列别名。我有我的查询工作。唯一的问题是AccountsDescription是实际的列名,我需要结果集来使用别名Account。有人能指出我正确的方向吗?

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

1 个答案:

答案 0 :(得分:2)

您撰写As AccountDescription的地方,请将其更改为As Account