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 |
|
ruchijani
Starting Member
23 Posts |
Posted - 2009-08-26 : 06:29:39
|
I have three table likeTable1SId Name1 abc2 def3 xyzTable2SId Col1 Col21 SS 31 ES 21 MS 32 SS 52 ES 42 MS 23 SS 23 ES 53 MS 4Table3Id Col3 Col41 SS 52 ES 53 MS 5and i want output like this in sql server 2000Sid Name SS ES MS1 abc 3 2 32 def 5 4 23 xyz 2 5 4 ThanksRuchi |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-08-26 : 07:20:05
|
| select t.sid,t.name,max(case when t2.col1 = 'ss' then t2.col2 end ) as 'ss',max(case when t2.col1 = 'es' then t2.col2 end ) as 'es',max(case when t2.col1 = 'ms' then t2.col2 end ) as 'ms'from table1 t inner join table3 t1 on t1.id = t.sid and t1.col3 = t.nameinner join table2 t2 on t2.sid = t.sid |
 |
|
|
ruchijani
Starting Member
23 Posts |
Posted - 2009-08-26 : 07:33:49
|
| Thank u for your reply But i cant use case in query because i want to generate it dynamically like if any one add another row in TABLE3 like [CODE]Table3Id Col3 Col41 SS 52 ES 53 MS 54[/CODE]ThanksRuchi |
 |
|
|
ruchijani
Starting Member
23 Posts |
Posted - 2009-08-26 : 07:44:55
|
| Thank u for your reply But i cant use case in query because i want to generate it dynamically like if anyone add rows in TABLE3 and TABLE2 like this[CODE]Table2SId Col1 Col21 SS 31 ES 21 MS 31 SW 12 SS 52 ES 42 MS 22 SW 13 SS 23 ES 53 MS 43 SW 2Table3Id Col3 Col41 SS 52 ES 53 MS 54 SW 5so output should look likeSid Name SS ES MS SW1 abc 3 2 3 12 def 5 4 2 13 xyz 2 5 4 2 so i want generate column of table3 dynamically according new records added [/CODE]ThanksRuchi |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-08-26 : 08:39:32
|
| go through this linkhttp://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/dynamic-crosstab-with-multiple-pivot-columns.aspx |
 |
|
|
ruchijani
Starting Member
23 Posts |
Posted - 2009-08-26 : 09:02:57
|
quote: http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/dynamic-crosstab-with-multiple-pivot-columns.aspx
Thank u so muchThanksRuchi |
 |
|
|
|
|
|