all groups > sql server mseq > october 2007 >
You're in the

sql server mseq

group:

Table Query


Table Query Ryan Mcbee
10/29/2007 7:06:01 PM
sql server mseq:
I have a table that has the following three fields and values that I am
trying to build a query on;

Column name-FEDERAL, FICA1, FICA2
Values- 1 , 100 , 200
2 , 300 , 400

How can I get a query to look like this?;
Column- TaxCode, Value
Values- FEDERAL , 1
FEDERAL, 2
FICA1, 100
FICA1, 300
FICA2, 200
FICA2, 400

I am doing this because I am trying to build a payroll report. The other
table that I am working with is structered like this.

Thanks,
Ryan
Re: Table Query Russell Fields
10/30/2007 12:00:00 AM
Ryan,

One easy way is:

SELECT 'FEDERAL', Federal
FROM MyTable
UNION ALL
SELECT 'FICA1', FICA1
FROM MyTable
UNION ALL
SELECT 'FICA2', FICA2
FROM MyTable

If you are on SQL Server 2005, you might also look at the UNPIVOT operator.

RLF

[quoted text, click to view]

AddThis Social Bookmark Button