• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Run a query inside a loop

Contributor ,
Mar 08, 2015 Mar 08, 2015

Copy link to clipboard

Copied

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!

Views

365

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 09, 2015 Mar 09, 2015

Copy link to clipboard

Copied

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,

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 11, 2015 Mar 11, 2015

Copy link to clipboard

Copied

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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 11, 2015 Mar 11, 2015

Copy link to clipboard

Copied

LATEST

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,

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation