David Williamson
asked on
create UPDATE query with CFLOOP
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?
<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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER