troubleshooting Question

Columns must turn to rows

Avatar of Glen Gibb
Glen GibbFlag for Canada asked on
Microsoft SQL Server
7 Comments1 Solution231 ViewsLast Modified:
Here's a query that almost gives what I need:

SELECT tblReportLines.NO3N AS [1st_Foot], tblReportLines_1.NO3N AS [2nd_Foot],
       tblReportLines.NO3N + tblReportLines_1.NO3N AS Total, SampleDate AS [Date] FROM tblReports
      INNER JOIN tblReportLines ON ReportFK = ReportPK
      INNER JOIN tblMonitoredSamples ON tblReportLines.SampleFK = tblMonitoredSamples.Soil1FK
      INNER JOIN tblReportLines tblReportLines_1 ON tblReportLines_1.SampleFK = tblMonitoredSamples.Soil2FK
      WHERE tblReportLines.ReportFK Between 1512 AND 1513

The resulting table looks like this:

     1st_Foot     2nd_Foot     Total     Date
---------------------------------------------------------
1.  2.1             2.3              4.4       20-Aug-2005
2.  3.1             3.5              6.6       29-Aug-2005

What I really need looks like this:

                      1        2         3        4
---------------------------------------------------------
1st_Foot         2.1    3.1       ...
2nd_Foot        2.4    3.5
Total              4.4    6.6
Date         20-Aug   29-Aug

Is there a way to rearrange the output?

Capt
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros