Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2012
    Posts
    3

    Unanswered: Retrieve data from database then Pivot/transpose?

    Hi,

    I was wondering if it was possible to query a data and then transpose it.

    This is what I have:

    Code:
    SELECT     gasQualityDefine.gqName AS GAP, sampledGasAnalysis.specificGravity AS 'SG',
    sampledGasAnalysis.CO2 AS 'C02',sampledGasAnalysis.N2 AS 'N2',sampledGasAnalysis.C1 AS 'C1',sampledGasAnalysis.C2 AS 'C2',sampledGasAnalysis.C3 AS 'C3',sampledGasAnalysis.IC4 AS 'IC4',
    sampledGasAnalysis.NC4 AS 'NC4',sampledGasAnalysis.IC5 AS 'IC5',sampledGasAnalysis.NC5 AS 'NC5',sampledGasAnalysis.C6plus AS 'C6+', sampledGasAnalysis.contractTime
    
    FROM         sampledGasAnalysis INNER JOIN
                          gasQualityDefine ON sampledGasAnalysis.gqId = gasQualityDefine.gqId
    
    WHERE     gasQualityDefine.gqname in ('001', '002', '003', '004', '005', '006', '007' )
    
    AND (sampledGasAnalysis.contractTime BETWEEN CONVERT(DATETIME, '2012-09-01 09:00:00', 102) AND CONVERT(DATETIME, '2012-10-01 08:59:00',102)) 
    
    AND (sampledGasAnalysis.auditVersion = 0) AND (sampledGasAnalysis.dataQuality = 10 OR
                          sampledGasAnalysis.dataQuality = 11)
    
    order by gqname
    And this is the result:

    GAP SG CO2
    001 # #
    002 # #
    003 # #
    004 # #
    005 # #
    006 # #
    007 # #


    But I would like to have the GAP on top like so:

    GAP 001 002 003 004 005 006 007
    SG
    CO2
    etc..

    Is it possible to do it like that?

    Thanks for the help

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Dec 2012
    Posts
    3
    I have done some googling prior posting, but can not seem to get it working........

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •