Skip to main content
May 14, 2008
Question

cfupdate action using query

  • May 14, 2008
  • 2 replies
  • 399 views
Hello Everyone,

I've got 2 datasources, each contaning 1 same table.
I need to copy a row from a table in datasource 1 to the table in datasource 2.
It's no problem to store all the data in variables and then to use the update statement, but my table contains a great number of columns, and the procedure is a bit messy.

I was wondering if it is possible to store all data from 1 row (alle columns) and use the cfupdate function to write all the data in one action.

Tnx for any help!
This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
May 18, 2008
You say cfupdate, so I'm assuming an existing row in the second datasource. Cfupdate needs the form scope, so you could do something like this:

<cfquery name="getRow" datasource="firstDsn">
select *
from tbl
where primaryKeyColName = {primary key value}
</cfquery>

<cfloop list="#getRow.columnlist#" index="colName">
<cfparam name="form[colName]" default="#getRow[colName][1]#">
</cfloop>
<!--- have assumed same table name --->
<cfupdate datasource="secondDsn" tablename="tbl">
update done

<!---
<cfinsert datasource="secondDsn" tablename="tbl">
--->




Inspiring
May 14, 2008
It might be possible. You'd be using cfinsert though, not cfupdate.