Link to home
Create AccountLog in
Avatar of usky1
usky1

asked on

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>
Avatar of msfletch
msfletch
Flag of United States of America image

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>
ASKER CERTIFIED SOLUTION
Avatar of msfletch
msfletch
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of usky1
usky1

ASKER

Works great thanks for the quick help.