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 |
|
hemant_ec48
Starting Member
7 Posts |
Posted - 2009-11-30 : 07:08:13
|
| Hi friends,How to achieve result like below.T1-----Q1-----A1""-----""-----A2""-----""-----A3""-----Q2-----B1""-----""-----B2""-----""-----B3""-----""-----B4Here T, Q, A are connected with each other...T=Testcode , Q=Question, A=AnswerTestcode Have Multiple Question, One question have Multiple answerSo If i select Testcode T1...Question Q1,Q2 will come...But Q1 have answer A1,A2,A3...My problem is...In Question column only one time Q1 should come....(in row of A1)remaining rows Q1 should not be come....(in rows of A2 & A3)same as for testcode...should apeear only once again all all questionLike in example...Hemant Patel Contact me : 09726242864 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-30 : 07:17:30
|
| Where do you want to show the data?MadhivananFailing to plan is Planning to fail |
 |
|
|
hemant_ec48
Starting Member
7 Posts |
Posted - 2009-11-30 : 07:25:57
|
| Hi MadhivananOne ASP page is already created....In which one table is created Which read Column header & rows....&...other reports also bind to that table.....same as above one is also one report...I can't change Existing ASP page.....So I need this functionality....Hemant Patel Contact me : 09726242864 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-30 : 07:30:48
|
| If you use reporting tool make use of it's Suppress if duplicated featureMadhivananFailing to plan is Planning to fail |
 |
|
|
hemant_ec48
Starting Member
7 Posts |
Posted - 2009-11-30 : 07:32:37
|
| Sorry dear...here app not using any reporting tool...headache is that this is classic ASP page.....and i can't change page...Hemant Patel Contact me : 09726242864 |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2009-11-30 : 07:41:46
|
| Will work only if u are using SQL 2005DECLARE @tbl AS TABLE(t VARCHAR(10),q VARCHAR(10),VALUE VARCHAR(10))INSERT INTO @tblSELECT 'T1','Q1','A1' UNION ALLSELECT 'T1','Q1','A2'UNION ALLSELECT 'T1' ,'Q1','A3' UNION ALLSELECT 'T1' ,'Q2','B1'UNION ALLSELECT 'T1','Q2','B2'UNION ALLSELECT 'T1','Q2','B3'UNION ALLSELECT 'T1','Q2','B4'SELECT CASE WHEN rowt=1 THEN t ELSE '' END AS t, CASE WHEN rowq=1 THEN q ELSE '' END AS q,VALUE FROM(SELECT *,ROW_NUMBER()OVER(PARTITION BY t ORDER BY t)AS rowt,ROW_NUMBER()OVER(PARTITION BY q ORDER BY q)AS rowqFROM @tbl)tPBUH |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-30 : 07:42:40
|
This is only for a funselect case when testcode_no=1 then testcode else '' end as testcode, case when question_no=1 then question else '' end as question, answer from(select testcode,Question,Answer, row_number() over (partition by testcode order by testcode) as testcode_no, row_number() over (partition by question order by testcode) as question_no from( select 'T1' as testcode,'Q1' as question,'A1' as answer union all select 'T1' as testcode,'Q1' as question,'A2' as answer union all select 'T1' as testcode,'Q1' as question,'A3' as answer union all select 'T1' as testcode,'Q2' as question,'B1' as answer union all select 'T1' as testcode,'Q2' as question,'B2' as answer union all select 'T1' as testcode,'Q2' as question,'B3' as answer union all select 'T1' as testcode,'Q2' as question,'B4' as answe) as t) as t MadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-30 : 07:50:16
|
MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|