|
Posted by Erland Sommarskog on 03/29/07 22:08
franzey (franzey@gmail.com) writes:
> Thanks for the link. I do only have SQL Server 2000 so the PIVOT is
> out. Looks like I will be doing some CASE statements. I'm new at this.
> Do you know the general syntax I would use using the above example to
> get this rolling?
From what you posted, there is nothing to identify which is Answer1, 2
and 3. Had there been, you could have run this query:
SELECT vID,
Answer1 = MAX(CASE answerno WHEN 1 THEN Answer END),
Answer2 = MAX(CASE answerno WHEN 2 THEN Answer END),
Answer3 = MAX(CASE answerno WHEN 3 THEN Answer END)
FROM tbl
GROUP BY vID
The MAX() here is a trick: we know that there is only one entry per
vID, so we could have used MIN() instead. MAX() is only there to get
all items on the same line.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
[Back to original message]
|