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 |
|
krishna_yess
Yak Posting Veteran
81 Posts |
Posted - 2009-12-08 : 06:07:59
|
i have a table like thisCAT NAME TEST_1A a 4A b 5A c 3A d 4A e 4A f 5B a 5B b 4B c 3B d 3B e 5B f 5 i need the output like thisNAME TEST_1_1 TEST_1_2a 4 5b 5 4c 3 3d 4 3e 4 5f 5 5 basically group by name but i need result in set of columns for each NAME group |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-12-08 : 06:13:20
|
are you using SQL 2000 or 2005/2008 ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
krishna_yess
Yak Posting Veteran
81 Posts |
Posted - 2009-12-08 : 06:24:22
|
| using sql 2005, should be compatible with 2000. need to move to production server which uses 2000 |
 |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2009-12-08 : 07:06:22
|
This?select Name, max(case when CAT = 'A' then TEST_1 end) as TEST_1_1, max(case when CAT = 'B' then TEST_1 end) as TEST_1_2from MyTablegroup by Name Ryan Randall - Yak of all tradesSolutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
krishna_yess
Yak Posting Veteran
81 Posts |
Posted - 2009-12-08 : 07:18:58
|
| exactly thats what i did, but CAT will grow like A,B ,C, D.....need to track CAT dynamicallyhow to do this |
 |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2009-12-08 : 07:38:51
|
| Then you need a dynamic pivot...[url]http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/dynamic-crosstab-with-multiple-pivot-columns.aspx[/url]Ryan Randall - Yak of all tradesSolutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
|
|
|
|
|