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 |
|
lemondash
Posting Yak Master
159 Posts |
Posted - 2009-11-26 : 07:33:12
|
| Hello all,I'm current using the below soloution/sql query to get a list of all the document types and how many they are. Each row has entered date. How can i put the latest entered date beside every different document type.SELECT DATEPART(YEAR, enteredon), sum(case when ldocumenttypeid = 1 then 1 else 0 end) AS [doctype1], sum(case when ldocumenttypeid = 2 then 1 else 0 end) AS [doctype2], sum(case when ldocumenttypeid = 3 then 1 else 0 end) AS [doctype3] FROM table1GROUP BY DATEPART(YEAR, enteredon)ORDER BY DATEPART(YEAR, enteredon)I would like to get the output as follows.[doctype1],enteredon, [doctype2], enteredon, [doctype3], enteredonany help would be great |
|
|
shaggy
Posting Yak Master
248 Posts |
Posted - 2009-11-26 : 08:02:36
|
| Use Pivot |
 |
|
|
lemondash
Posting Yak Master
159 Posts |
Posted - 2009-11-26 : 08:48:04
|
| Would that still be possible with a sql server 2000 (8.0)database ? |
 |
|
|
|
|
|