Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

Pivot Table

I need to create a pivot table, but I am not getting the results that I need.  I have the following data in a single table

QuestID       CustID       Results          Timestamp
--------------------------------------------------------------
Q1                      1            2/10/2004    2011-03-02 11:52am
Q2                      1            Yes               2011-03-02 11:52am
Q3                      1            Fridays         2011-03-02 11:52am
Q1                      2            2/16/2006    2011-03-02 1:52pm
Q2                      2            No                2011-03-02 1:52pm
Q3                      2            Sundays       2011-03-02 1:52pm

I need to pivot the QuestID, so the results would look more like this.

CustID          Q1            Q2               Q3          Timestamp (the timestamp is the same for all questions)
-------------------------------------------------------------------------------------------------------------
1              2/10/2004     Yes         Fridays       2011-03-02 11:52am
2              2/16/2060     No          Sundays     2011-03-02 1:52pm

Any help or direction would be greatly appreciated

Thanks,
0
clintnash
Asked:
clintnash
1 Solution
 
tigin44Commented:
try this


SELECT CustID, [Q1], [Q2], [Q3], [Q4], Timestamp
FROM (
      select QuestID ,CustID ,Results,Timestamp
      from yourTable
      ) P
      PIVOT
      (
            MAX(Results) FOR QuestID IN ([Q1], [Q2], [Q3], [Q4])
      ) AS PVT
0
 
clintnashAuthor Commented:
MAX(results) is what I was missing.  Thank you very much !!!
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now