create UPDATE query with CFLOOP

Posted on 2003-11-18
Last Modified: 2013-12-24
I would like to create a query based on CFLOOP.  I need to update a undetermined number of numerically-named fields.  After the loop is processed, I am looking for the following example to be what the MySQL server gets:

<cfquery datasource="DSN">
UPDATE myTable
SET Field = 'Form.Field1',
       Field = 'Form.Field2',
       Field = 'Form.Field3',
WHERE x = y

I was thinking that the code could be something like this:

<cfquery datasource="DSN">
UPDATE myTable
SET dummy=0
<cfloop from="1" to="#NumberOfLoops#" index="i">
       ,Field = '#Form.Field#i##'
WHERE x = y

However, I don't know if you can nest variables like this.  How could I accomplish what I'm describing?
Question by:theamzngq
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

Accepted Solution

CFDevHead earned 100 total points
ID: 9771877
Try this.

<cfquery datasource="DSN">
UPDATE myTable
SET dummy=0
<cfloop from="1" to="#NumberOfLoops#" index="i">
       ,Field = '#evaluate("Form.Field"  &  i)#'
WHERE x = y

Author Comment

ID: 9774880
That did it, thank you for expanding my knowledge...

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

623 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