Re: Combine multiple records into single row
- From: Erland Sommarskog <esquel@xxxxxxxxxxxxx>
- Date: Thu, 29 Mar 2007 22:08:46 +0000 (UTC)
franzey (franzey@xxxxxxxxx) 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, 2and 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@xxxxxxxxxxxxx
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
.
- References:
- Combine multiple records into single row
- From: franzey
- Re: Combine multiple records into single row
- From: Jason Lepack
- Re: Combine multiple records into single row
- From: franzey
- Combine multiple records into single row
- Prev by Date: Re: Newbie on permissions: ADO.NET, C++.NET, SQL SERVER 2005 EXPRESS, Visual Studio 2005
- Next by Date: Re: Run query based on values in another table
- Previous by thread: Re: Combine multiple records into single row
- Next by thread: Re: Combine multiple records into single row
- Index(es):