House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home / Groups / ColdFusion Talk (CF-Talk)

Data pivot problem (brain isn't working right today)

Author:
Maureen
03/10/2010 06:46 PM

Syntax not exact, but this is the process. <cfquery name="getStrats> Select Stratification from Target_Stratifications </cfquery> <cfquery name="getTargets"> Select Target_Type from Target_Types </cfquery> <table> <!--- Set headings ---> <tr> <td>Name</td> <cfloop query = "getTargets"> <td>#Target_Type#</td> </cfloop> </tr> <!--- Do Table ---> <cfloop query = "getStrats"> <tr> <td>#Stratification#</td>    <cfloop query = "getTarget">    <cfquery name= "getTargetTargets">     select * from Target_Targets     where Stratification = getStrats.Stratification and Target_type = getTargets.Target_type    </cfquery>    <td>#getTargetTargets.Target#</td>    </cfloop> </tr> </cfloop> </table> > > Hi all, > > > > Got a problem trying to convert a many to many relationship to a grid. > > > > There are three tables (defined below), and I need the output in a > certain way (also defined below). I've done this before, but for the > life of me I can't remember how. > > > > Table 1 (Target_Stratifications): > > Stratification varchar(100) not null primary key > > Strat_owner varchar(100) not null > > > > Table 2 (Target_Types): > > Target_type varchar(15) not null  primary key > > Target_default numeric(9, 4) not null default 0 > > Target_Tolerance numeric(9, 4) not null default 0 > > > > Table 3 (Target_Targets): > > Stratification varchar(100) not null > > Target_type varchar(15) not null > > Target numeric(9, 4) not null default 0 > >  *Primary Key (stratification, target_type) > >  * [Stratification] References Target_Stratifications.stratification > [on update cascade, on delete cascade] > >  * [target_type] References Target_Types.target_type [on update > cascade, on delete cascade] > > > > It's a pretty normalized set of tables. In stratifications is a list of > proper names, and in target types is the Proper name for the target of > the measure that is being worked on along with default values and > tolerances. > > > > I need to get the data in this format (| used just to separate the > columns, the actual result will be put in a cfgrid): > > Stratification|Target_Type(1)|Target_Type(2)|Target_Type(3)|Target_Type( > 4)|...|Target_Type(n) > > Steve|100|50|25|10|...|15 > > Mike|25|75|2|100|...|75 > > > > Can someone push me in the right direction? > > > > Thanks, > > Steve > > > > > >


Search cf-talk

July 31, 2010

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
         1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31