1 Reply Latest reply: Oct 27, 2013 8:03 AM by Andreas Weiden RSS

    passing check box values to WHERE clause

    akm006

      Hi,

       

      I have created a Data block - 'CONTACT' (Database data block)

      and has database item - 'Code', 'Descr'

       

      The number of records displayed is set to 5.

       

      Value When checked - 'Y'

      Value When Unchecked - 'N'

      Check box mapping of other values - 'unchecked'


      I am writing the code inside 'WHEN BUTTON PRESSED'. My main objective is to return the count of records based

      based on several conditions and one among them is CODE which is can be single or multiple based on the checkbox checked.

       

      The requirement is when i check one or multiple checkboxes, i should pass the 'Code' item values to the WHERE clause.

       

      I have tried using basic loop but things havmt worked as shown below.

       

      The next_record refers to the UNTICKED CHECKBOX as well and thereby returning all the rows eventhough if it is not checked.

       

      ----------------------------------------------------------------------------

      --LOOP

      IF :contact.cb = 'Y' THEN

      LOOP

       

      IF p_where is null then

       

      p_where := :contact.code;

       

      else

       

      p_where := p_where ||','||:contact.code;

       

      end if;

       

      exit when :system.last_record = 'TRUE';

      next_record;

       

      END LOOP;

       

      end if;

       

      -- END LOOP;

      MESSAGE ( 'p_where :'||p_where);

      MESSAGE (' ');

       

      END;


      ------------------------------------

       

      And Even if i write the LOOP before the first IF, it return me the current record value and move to the last record.

       

      Please suggest

        • 1. Re: passing check box values to WHERE clause
          Andreas Weiden

          Try something like this:

           

          FIRST_RECORD;
          
          LOOP
          
            IF :contact.cb = 'Y' THEN
              IF p_where is null then
                 p_where := :contact.code;
               else
                 p_where := p_where ||','||:contact.code;
               end if;
             END IF;
            exit when :system.last_record = 'TRUE';
            next_record;
          END LOOP;
          
          -- END LOOP;
          MESSAGE ( 'p_where :'||p_where);
          MESSAGE (' ');
          
          END;