Skip to main content
Inspiring
March 9, 2015
Question

Run a query inside a loop

  • March 9, 2015
  • 1 reply
  • 574 views

Hi All,

I need to run a query inside a loop; and the query will be running for more than 100 times.

Is there anyway to do other than this.

Based on the value, the query will be running;  I cannot do queries of queries.

Thanks in advance!

    This topic has been closed for replies.

    1 reply

    WolfShade
    Legend
    March 9, 2015

    It is RARELY, if ever, a _good_ idea to put a query within a loop.  Every iteration will be a connect / query / disconnnect.  Bad mojo.  It should be done ONLY if there is no alternative.

    Without knowing the context of what you really need to do, we can't really help.  Can you provide details of what needs to be done?

    V/r,

    ^_^

    meensiAuthor
    Inspiring
    March 11, 2015

    Here we go , there is a Table A which has got all the values which I need.

    I need to compute a value based on 4 columns ( one is Table B, second is Table C and third is Table D and fourth is from Table A)..

    so while displaying the results i need to display some columns + Computed column.

    When running inside a cfloop, i m executing the query to compute the column which i needed.

    I cannot pre compute this and have it in my Database;

    WolfShade
    Legend
    March 11, 2015

    Have you attempted doing this with a LEFT OUTER JOIN (if you need data from Table A regardless of related data in any other table) or a standard JOIN (if you DON'T want data from Table A if there is no related data in another table)?

    If you are using PL-SQL or T-SQL, is there no way to calculate the necessary values on-the-fly within a JOIN query?

    May I see the query that you currently have in place inside the loop?

    V/r,

    ^_^