Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Table from Vertical to horizontal
Message
 
 
À
07/12/2008 02:26:06
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Divers
Thread ID:
01365804
Message ID:
01365835
Vues:
13
>Thank you Naomi for your help, I will try to explain.
>I have a table called report which include the following structure
>student_id
>name
>subject
>mark
>
>a sample of the data
>ID   NAME   MARK                 SUBJECT
>1    AAA      11               MATH
>1   AAA       12               BIOLOGY
>1   AAA      12                ENGLISH
>1  AAA       14                CIVIC
>1  AAA       15                HISTORY
>2  BBB       7                 CHEMSTRY
>2  BBB       2                 MATH
>2  BBB       22                BIOLOGY
>2  BBB      21                 MATH
>3  CCC      31                 MATH
>3  CCC      34                 CIVIC
>3  CCC      35                 HISTORY
>3  CCC      37                ECONOMIC
>THIS TABLE SHOULD BE CONVERTED TO  ANOTHER TABLE AS FOLLOW
>
>STUDENT ID    NAME    SUBJECT 1     SUBJECT 2      SUBJECT 3      SUBJECT 4    SUBJECT 5
>1                     AAA       MATH              BIOLOGY         SPANISH        CIVIC               HISTORY
>2                     BBB       MATH              BIOLOGY          
>
>this is where exactly I stack since 10 days, if only I can create a report horizentaly from a vertical table my problem is solved.
1. 

   Select distinct subject from Report into cursor c_UniqueSubjects nofilter

2. local lcSubjects, lnCount, 
    lcSubjects = ""
    select c_UniqueSubjects
   lnCount = 0
   scan
      lcSubjects = ", "  + Subject + " I"
      local &Subject  
   endscan

3.  create cursor c_FinalResult (iID I, cStudentName C(40) &lcSubjects)
   && If this would not work, we can construct the whole create cursor command as a string
   index on iID tag iID

4.  select Report
     set order to StudentID
    scan
         if not seek(StudentID, 'c_FinalRersult')
             insert into c_FinalResult (iID, cStudentName) values (Report.ID, Report.Name)
         endif
           store Reprt.Mark to ("m." + Subject)
           replace (Subject) with ("m." + Subject) in c_FinalResult
    endscan
All of this from the top of my head and not tested/optimized, but should give you an idea.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform