1 Reply Latest reply on Jun 26, 2013 7:16 AM by shawkins

    Virtual procedure store select results in variable

    neetacomp

      I am looking for some thing like below

       

      variable myCount;

       

      select count(1) from table1;

       

      if count > 0

       

      select * from table2

       

      else

       

      select * from table 2

       

       

      So can I have multiple select statements in my procedure. If yes, how will it take care of Resultset?

      This is simple logic. I still want to write complex logic with select from multiple tables and use lot of if else criteria. Can I perform all these things using Virtual procedure?

       

      How can I store my first query results in variable myCount?

       

      Thanks,

      Neeta

        • 1. Re: Virtual procedure store select results in variable
          shawkins

          > So can I have multiple select statements in my procedure. If yes, how will it take care of Resultset?

           

          Yes you can.  The expectation is that all returnable (the default) statement should match the expected resultset of the procedure if one is defined.

           

          > Can I perform all these things using Virtual procedure?

           

          Yes that should be fine.

           

          > How can I store my first query results in variable myCount?

           

          You would use a scalar subquery:

           

          {code}declare integer myCount = (select count(1) from table1);{code}

           

          Steve