Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Loop a Query

Posted on 2008-06-11
3
221 Views
Last Modified: 2013-12-24
Can I add the cfloop below to my cfquery statement?

<cfset counter=0>
<cfloop index="i" list="#CIDS#" delimiters=",">
<cfset counter=counter+1>
      <cfset "CIDS#counter#"=i>
</cfloop>
<cfloop index="j" from="1" to="#counter#">
<cfoutput>#variables["CIDS" & j]#</cfoutput>
</cfloop>
<cfquery  name="get_CIDS" datasource="#request.dataSource#">
      SELECT customerno, customer_first1, customer_last1
      FROM cibIDS
      WHERE customerno = <cfqueryparam value="#customerno#" maxlength="6"> AND
            CID =( How do I loop through the above cfloop and get the values to insert here?)
</cfquery>
0
Comment
Question by:usky1
  • 2
3 Comments
 
LVL 4

Expert Comment

by:msfletch
ID: 21763502
Try creating a list from the loop and then adding the list to the query like:

<cfquery  name="get_CIDS" datasource="#request.dataSource#">
      SELECT customerno, customer_first1, customer_last1
      FROM cibIDS
      WHERE customerno = <cfqueryparam value="#customerno#" maxlength="6"> AND
            CID IN (#loopList#)
</cfquery>
0
 
LVL 4

Accepted Solution

by:
msfletch earned 500 total points
ID: 21763511
Or just include the lidt directly:

CID IN (#CIDS#)

0
 

Author Closing Comment

by:usky1
ID: 31466295
Works great thanks for the quick help.
0

Featured Post

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question