Reply to Re: Combine multiple records into single row

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация