SQL Transpose rows to columns
Posted on 2009-05-18
I am trying to solve a problem in SQL but can't seem to get it solved.
I need to get sql 2000 table information into a table that resides within a Word Document that looks just like this.
Medical Payments: $ 1,001 $ 1,005 $ 1,002
Perils Deductible: $ 1,001 $ 1,010 $ 1,001
Hurricane Deductible: 2% 3% 2%
Premium: $ 401 $ 405 $ 410
Company: XXXCo YYYCo ZZZCo
The SQl 2000 table looks like this:
company Premium PerilsDeduct Hurricandeduct Medical
xxxco 401 1001 2 1001
zzzco 410 1001 2 1002
yyyco 405 1010 3 1005
The column on the left will NOT change when merging. So you can see I need to transpose rows into columns. It's not going to be simply a "1 to 1" transpose because I'll be selecting what records to merge based on another value that is not in this SQL table. I think this is a tough issue and would be very grateful for help. I can't use the pivot function because it's sql 2000.