Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Permuting a query N times
Message
From
29/11/2007 13:00:29
Luis Navas
Independent Consultant
Auckland, New Zealand
 
 
To
29/11/2007 11:40:18
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01271938
Message ID:
01272124
Views:
26
Thank a lot Dragan and Al.


I have to build a text file depending of the values, so I need to query every time the table but the filter condition will be being more complex, depending of the level, for example
Lparameters lnManufacter As Integer, lnBrand As Integer
lcOrder="012345" && but it can be in any permutation of the characters 720 in total
*Remember 0=Weight, 1 Characteristic 1,2 Characteristic 2, etc
Select Acts
Scan
  If Left(lcOrder,1,1)="0"
     Select Distinct Weight From Acts Where idManufact=lnManufacter And idBrand=lnBrand Into Cursor Weights ReadWrite
     Scan
        lnWeight=Acts.idWeight
        Insert Into Parameters (Text) Values (">Manufacter")
        Insert Into Parameters (Text) Values (">>Brand")
        Insert Into Parameters (Text) Values (">>>Weight")
        If Len(lcOrder)>1
          Do Case
             Case Left(lcOrder,2,1)="1"
                Select Distinct Charac1 From Acts Where idManufact=lnManufacter And idBrand=lnBrand ;
                and idWeight=lnWeight Into Cursor Characts1 ReadWrite
                Scan
                   lnChar1=Acts.idChar1
                   Insert Into Parameters (Text) Values (">Manufacter")
                   Insert Into Parameters (Text) Values (">>Brand")
                   Insert Into Parameters (Text) Values (">>>Weight")
                   Insert Into Parameters (Text) Values (">>>>Char 1")
                   If Len(lcOrder)>2
                     Do Case
                        Case Left(lcOrder,3,1)="2"
                          Select Distinct Charac2 From Acts Where idManufact=lnManufacter And idBrand=lnBrand ;
                          and idWeight=lnWeight And idChar1=lnChar1 Into Cursor Characts2 ReadWrite
                          Scan
                            lnChar2=Acts.idChar2
                            Insert Into Parameters (Text) Values (">Manufacter")
                            Insert Into Parameters (Text) Values (">>Brand")
                            Insert Into Parameters (Text) Values (">>>Weight")
                            Insert Into Parameters (Text) Values (">>>>Char 1")
                            Insert Into Parameters (Text) Values (">>>>>Char 2")
                            If Len(lcOrder)>3
&&                                 .....
                            EndIf  
                          EndScan
                        Case Left(lcOrder,3,1)="3"
                        *More Cases....
                     EndCase
                   EndIf  
                EndScan
             Case Left(lcOrder,2,1)="1"  
             *More Cases....
          EndCase
        EndIf
     EndScan
  EndIf
EndScan
That is the algorithm in a hard way, imagine I will have to write it for 720 different permutations, what I want is a way to do it for N permutations, is more clear now?

Thanks a lot for your time

Luis Navas



>>Hi to all, I have a tricky one (at least for me), I need to create a recursive query of the same table, let me explain a little more:
>>
>>
>>I have a table with these fields as structure and some sample data:
>>Category___Manufacturer____Brand________Weight_____Characteristic1_Char2___Char3______Char4_______Char5
>>Cereals_______Kellogs_________Corn Flakes__300 Gr_____Box_____________Natural_Corn_______No Def______No Def
>>Sodas_________Coca Cola Comp__Coca Cola____2000 Ml____Glass___________Cola____Light______No Def______No Def
>>Female Prot___Kimberly Klark__Kotex________12 Units___With Wings______Thin____with smell_Good Nights_No Def
>>
>>The fields characteristic 1 to 5 could be different attributes for each category, like type of package, flavor, model, etc.
>>
>>I have another table, with a field Character(6) that holds the order of the way that the user needs to see the information, I use six because Category, Manufacturer and Brand use the same order 0,1,2 respective.
>>The users decides the order of the other parts 0 for Weight, 1 for characteristic 1, 2 for characteristic 2 and so on.
>
>You can have a moverbox, with list of fields on the left, and sorting fields on the right. Then the user would pick six fields from the left, and arrange them on the right. Then when the user clicks OK, you'd build an Order By clause from the right side list, and then either insert it into your SQL statement as a macro, or build the whole SQL statement as a script and run it via execscript() - your choice. The resulting cursor would be in the order user wanted.
>
>Or you can have data selected already in any order in crsTemp, and have a cursor for your grid, then
>
>
zap in gridCursor
>insert into gridCursor ;
>   select * from crsTemp ;
>   order by &lcOrder
>assuming VFP8 or 9 (not sure insert into works in 7 or earlier, but then you can append from dbf("crsTemp") instead).
I never forget a face, but in your case I will make an exception :-)
Previous
Reply
Map
View

Click here to load this message in the networking platform