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 |
|
ganny
Yak Posting Veteran
51 Posts |
Posted - 2009-04-02 : 02:30:39
|
| Hi all,Below is my table with three columns:Parent Child Incharge------------------------A100 X414 KDLA100 U541 KDLA100 O554 KDLB200 K641 KDLB200 S774 KDLC300 Y455 KDLD400 Z475 KDLI would like to show the above table as below:Parent Child Incharge------------------------Parent A100 -A100 X414 KDLA100 U541 KDLA100 O554 KDLParent B200 -B200 K641 KDLB200 S774 KDLParent C300 -C300 Y455 KDLParent D400 -D400 Z475 KDLKindly assist me how to do this. Thanks. |
|
|
ayamas
Aged Yak Warrior
552 Posts |
Posted - 2009-04-02 : 03:03:38
|
| declare @tbl table(Parent varchar(20),Child varchar(20),incharge varchar(30))insert into @tblselect 'A100', 'X414','KDL' union allselect 'A100', 'U541','KDL' union allselect 'A100', 'O554', 'KDL' union allselect 'B200', 'K641','KDL' union allselect 'B200', 'S774','KDL' union allselect 'C300', 'Y455', 'KDL' union allselect 'D400', 'Z475', 'KDL'select case when child is null and incharge is null then 'Parent' + ' ' + Parent else Parent end,child,incharge from(select Parent,child,incharge from @tblgroup by Parent,Child,inchargewith rolluphaving GROUPING(Parent)^GROUPING(Child)^GROUPING(incharge)=0)torder by Parent,child |
 |
|
|
|
|
|
|
|