We help IT Professionals succeed at work.
Get Started

cfquery update with cffunction fails

ShanghaiD asked
Last Modified: 2012-05-12
I have a cffunction name="TidyClientNames" to perform complex REGEX modifications on ClientName strings.  I want to use this cffunction to update a MySQL table field.

I can do this successfully by querying the target MySQL table and then looping over the result when I then execute an UPDATE query for each iteration of the loop, as follows:

<cfquery name="OldNames">
  SELECT clientcode, clientname 
  FROM tempClients

  <cfloop query="OldNames">
    <cfquery name="update">
      UPDATE tempClients
      SET clientname = '#TidyClientNames(clientname)#'
      WHERE clientcode = '#clientcode#'

Open in new window

However, execution time is slow and I want to speed this up if I can.

I tried to call the cffunction more directly in a single cfquery UPDATE as follows (but this fails):

<cfquery name="TidyNames">
  UPDATE tempClients
  SET clientname = '#TidyClientNames(clientname)#'

Open in new window

When I run this alternative query (instead of the earlier cfquery and cfloop and cfquery). I get an error message:

Variable CLIENTNAME is undefined. 

Open in new window

What am I doing wrong?  How can I fix things?

Watch Question
Most Valuable Expert 2015
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE