3 Replies Latest reply: Nov 8, 2013 7:52 AM by Jonathan Dienst RSS

    Looping while loading the data

      I want to load the data within a loop. The following is my case,

       

      General logic:

      my_data:

      ResultSet resultSet = "Select distinct designation, location from employee";

      for(int i = 0; i < resultSet.count; i++) {

      load emp_id,

          name,

          designation, location, salary;

      sql select * from employee where location = "resultSet[i].location" , designation = "resultSet[i].designation";

      }

       

      I want the above logic should be done while loading the data. Every time it should concatenate/append with the existing data.


      Please help me to get this done.

        • Re: Looping while loading the data
          Anna fuksa

          can you attach a file ?

          • Re: Looping while loading the data

            Hi Rajaram,

             

            "For next" as well as "For each next" is described with examples in the reference manual. If you have done a full installation of QlikView you can find it here :


            C:\ProgramData\QlikTech\QlikView Documentation\Reference Manual


            /Ida

            • Re: Looping while loading the data
              Jonathan Dienst

              Hi

               

              I think this is what you are looking for:

               

              tmpLocationDesignation:

              LOAD Distinct

                   Location,

                   Designation

              From employee;

               

              For i = 1 To NoOfRows('tmpLocationDesignation')

               

                   Let zLocation = Peek('Location', i, 'tmpLocationDesignation');

                   Let zDesignation = Peek('Designation', i, 'tmpLocationDesignation');

               

                   my_data:

                   load emp_id,

                        name,

                        designation,

                        location,

                        salary;

                sql select * from employee

                where location = '$(zLocation)'  And designation = '$(zDesignation)';

               

              Next

               

              Set zLocation =;

              Set zDesignation =;

              Drop Table tmpLocationDesignation;

               

              HTH

              Jonathan