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 |
|
Kalaiselvan
Posting Yak Master
112 Posts |
Posted - 2011-09-26 : 03:30:43
|
| Table1:[Column1] [Column2] [Column3] AAA FFF JJJ BBB GGG KKK CCC HHH IIIThe above table as 3 columns and some rows respectively. Need the result from above table as[C1][C2][C3]AAA FFF JJJAAA FFF KKKAAA GGG JJJAAA GGG KKKAAA HHH JJJAAA HHH KKKAAA III JJJAAA III KKKBBB FFF JJJBBB FFF KKKBBB GGG JJJBBB GGG KKKBBB HHH JJJBBB HHH KKKBBB III JJJBBB III KKKCCC FFF JJJCCC FFF KKKCCC GGG JJJCCC GGG KKKCCC HHH JJJCCC HHH KKKCCC III JJJCCC III KKKIts like Attretion Matrix method. Column1 as 3 rows, Column2 as 4 rows and Column3 as 2 rows. 3*4*2=24 rows will be the result.Please help me to get the solution for this...Regards,Kalaiselvan RLove Yourself First.... |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-26 : 04:06:43
|
| [code]SELECT a.Column1,b.Column2,c.Column3FROM (SELECT DISTINCT Column1 FROM Table1) aCROSS JOIN (SELECT DISTINCT Column2 FROM Table1) bCROSS JOIN (SELECT DISTINCT Column3 FROM Table1) c[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Kalaiselvan
Posting Yak Master
112 Posts |
Posted - 2011-09-26 : 08:34:17
|
| Thanks its working fine. Like the same If the Columns count were Dynamic, how we can use the same process to get the result.For Ex; In above Table1 we have 3 columns. If we doesnt know the Column name and its count.Ex: Table1 --> (Below Example)Table 2 --> [Column1] [Column2] [Column2] [Column4] AA FF KK RR GG LL SS HH TTTable2 will have 1*3*2*3=18 rows of values. Like the same Many tables can created and we need to Built a Query for this Attretion.Please help me in this to get the Solution too.Regards,Kalaiselvan RLove Yourself First.... |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-26 : 09:21:04
|
| sorry but i cant see the need of all this. what the purpose of this requirment? why your columns are dynamic?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Kalaiselvan
Posting Yak Master
112 Posts |
Posted - 2011-09-27 : 11:24:39
|
| Ita a CRM project. Here the table will be created dynamically.Regards,Kalaiselvan RLove Yourself First.... |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-27 : 12:22:21
|
| then you've to use dynamic sql. for getting column names dynamically make use of INFORMATION_SCHEMA.COLUMNS catalog view------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|