SQL newbie
SQL newbie

Reputation: 1

How to use a column alias in a Select Case When Grouping

I'm a trying to figure out how to use a column alias in a select case when grouping. I've got my query to work. The only problem is AccountsDescription is the actual column name and I need the result set to use the alias Account instead. Can someone point me in the right direction?

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

Upvotes: 0

Views: 1240

Answers (1)

John Pick
John Pick

Reputation: 5650

Where you wrote As AccountDescription, change it to As Account.

Upvotes: 2

Related Questions