Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2007-03-20 : 09:06:36
|
Jon writes "I am joining three tables in a SQL Query and exporting the data into an Excel Spreadsheet. I'm not sure how to explain the problem (still new at most of this), so here is a kind of representation...The Spreadsheet currently looks like this (same way SQL pulls it)LastName FirstName Class DateDoe John Class1 3/18/2007Doe John Class2 3/27/2007Doe John Class3 4/21/2007 (etc)I need it to look like this:LastName FirstName Class1 Class2 Class3 Doe John 3/18/2007 3/27/2007 4/21/2007 Sorry if that's confusing, but any help you could provide would be much appreciated. I am using SQL Server 2000 Standard (no service pack at the moment) and Windows 2K SP4 (on server). Desktop that Excel spreadsheet is going to is Windows XP SP2." |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-20 : 09:18:43
|
[code]select LastName, FirstName, Class1 = max(case when Class = 'Class1' then Date end), Class2 = max(case when Class = 'Class2' then Date end), Class3 = max(case when Class = 'Class3' then Date end)from tablegroup by LastName, FirstName[/code] KH |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-04-02 : 05:54:20
|
| Also, you can make use of EXCEL's PIVOT featureMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|