Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

create UPDATE query with CFLOOP

Posted on 2003-11-18
2
Medium Priority
?
641 Views
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
</cfquery>

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##'
</cfloop>
WHERE x = y
</cfquery>

However, I don't know if you can nest variables like this.  How could I accomplish what I'm describing?
0
Comment
Question by:theamzngq
[X]
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
2 Comments
 
LVL 9

Accepted Solution

by:
CFDevHead earned 400 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)#'
</cfloop>
WHERE x = y
</cfquery>
0
 
LVL 2

Author Comment

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

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
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 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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

722 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