Question : SQL Statement - seperate single column into 3 different data columns

I have a SQL 2005 dataview that has a single column TAX and a single column TAXCODE. The TAX column has all tax values in a single column - meaning every invoice has 3 lines of data. The three lines are state, fed, and county. I wish to display in single line of data but put the TAX column into 3 differnet columns based on TAXCODE. EXAMPLE: TAXCODE=2 in a column that says STATE and TAXCODE=3 is FED and TAXCODE=4 is COUNTY. I want my 3 lines of data into 1 line of data.

This is my sample code:
SELECT     Invoiced.CustomerID, Invoiced.InvoiceNumber, Invoiced.Tax, Invoiced.TaxCode
FROM         dbo.ARInvoiceHeader

 

Answer : SQL Statement - seperate single column into 3 different data columns

try this
1:
2:
3:
4:
5:
6:
select CustomerID,InvoiceNumber,
       max(case when TaxCode = 2 then TotalTaxLocalAmount end) as State,
       max(case when TaxCode = 3 then TotalTaxLocalAmount end) as Fed,
       max(case when TaxCode = 4 then TotalTaxLocalAmount end) as County
  from dbo.Z_TaxProject
 group by CustomerID,InvoiceNumber
Random Solutions  
 
programming4us programming4us