• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

Loop a Query

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
usky1
Asked:
usky1
  • 2
1 Solution
 
msfletchCommented:
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
 
msfletchCommented:
Or just include the lidt directly:

CID IN (#CIDS#)

0
 
usky1Author Commented:
Works great thanks for the quick help.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now