<!--------------------------------------------------------
This example will work with several database programs, such
as MS Access, SQL Server, Informix, Oracle.
--------------------------------------------------------->
<!--------------------------------------------------------
Declare an array...
--------------------------------------------------------->
<CFSET records = ArrayNew(1)>
<!--------------------------------------------------------
Get all records...
1) Replace 'myODBCDSN' in BOTH queries below with your
ODBC or OLE DB connection
to your database - under Cold Fusion Administrator -> ODBC
section. The connection to your database must have read and
update permissions.
2) Replace 'myTableName' with the name of the table.
--------------------------------------------------------->
<CFQUERY Name="getMyRecords" DataSource="myODBCDSN">
SELECT ID
FROM myTableName
</CFQUERY>
<!--------------------------------------------------------
Set all records...
--------------------------------------------------------->
<CFLOOP QUERY="getAllCustomerIds">
<CFSET records[ArrayLen(records)+1]=#ID#>
</CFLOOP>
<!--------------------------------------------------------
For each array element...
--------------------------------------------------------->
<CFLOOP Index="index" FROM="1" TO="#ArrayLen(records)#" STEP="1">
<CFSET ID2 = records[index]>
<CFSET IDNew = Mid(ID2, 1, 1) & Mid(ID2, 4, Len(ID2)-3)>
<CFQUERY Name="updateMyRecords" DataSource="myODBCDSN">
UPDATE myTableName
SET IDNew = #IDNew#
</CFQUERY>
</CFLOOP> |