Updating data in a column using it's own value

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Updating data in a column using it's own value

    I trying to change all the entries in a column of a table to titlecase. I have
    a custom tag that does the case change but I can't get it to work in the
    following query:

    <cfquery name="UpdateRes" datasource="#application.dsn#">
    UPDATE idx_res
    SET city = <cf_changecase case="titlecase" string="#city#"
    result="convCity">'#convCity#'
    </cfquery>

    I get a variable not found error for #city#. It must not recognize it because
    it's coming from the same table.

    Is there a way to work around this?

    drmaves Guest

  2. Similar Questions and Discussions

    1. updating XML data
      I have the following code in place to move a variable from my Flash app to an XML file for storage . . . //replace the GoodVN value in the XML...
    2. Getting column data without column names
      Hello all, I'm trying to write a coldfusion program to display account data such as name, address, phone #, etc. I retrieve this data from an ...
    3. Updating data sent from Paypal
      I have a value sent from paypal that I am trying to insert into an existing database. I am trying to call up the data, from the existing...
    4. Template Column data depending on form data
      Langauage C# I have a webform containing a dropdown control and a datagrid. A different query is fired depending on the value of the dropdown...
    5. Updating Data Using a Subform
      On Tue, 8 Jul 2003 12:27:39 -0700, "Brian" <btvisc@hotmail.com> wrote: Base the Subform on a Query with a criterion of on the date/time...
  3. #2

    Default Re: Updating data in a column using it's own value

    check if this works for u ...

    <cfquery name="qGetNames" datasource="#application.dsn#">
    select city from idx_res
    </cfquery>
    <cfloop query="qGetNames">
    <cfquery name="UpdateRes" datasource="#application.dsn#">
    UPDATE idx_res
    SET city = <cf_changecase case="titlecase"
    string="#qGetNames.city#" result="convCity">'#convCity#'
    </cfquery>
    </cfloop>

    adonis1976 Guest

  4. #3

    Default Re: Updating data in a column using it's own value

    It almost worked but not quite.

    The script changed the case of the first record and then used that value for
    all the records as the replacement.

    Every record's city value is now the same.

    Any idea on why each record wasn't processed idependently?

    drmaves Guest

  5. #4

    Default Re: Updating data in a column using it's own value

    because you don't have a WHERE clause in your update query. It's doing exactly what you told it to do.
    Kronin555 Guest

  6. #5

    Default Re: Updating data in a column using it's own value

    Okay, that makes sense. I put a WHERE clause in my UPDATE query but it doesn't
    recognize qGetNames.
    I get the follow error message: Unknown table 'qGetNames' in where clause.
    What do I need to do to get it to recognize it?

    Here's where my code stands now:

    <cfquery name="qGetNames" datasource="#application.dsn#">
    SELECT city, listing_num
    FROM idx_res
    </cfquery>

    <cfloop query="qGetNames">
    <cfquery name="UpdateRes" datasource="#application.dsn#">
    UPDATE idx_res
    SET city = <cf_changecase case="titlecase" string="#qGetNames.city#"
    result="convCity">'#convCity#'
    WHERE idx_res.listing_num = qGetNames.listing_num
    </cfquery>
    </cfloop>

    drmaves Guest

  7. #6

    Default Re: Updating data in a column using it's own value

    this is what u need:

    <cfquery name="qGetNames" datasource="#application.dsn#">
    SELECT city, listing_num
    FROM idx_res
    </cfquery>

    <cfloop query="qGetNames">
    <cfquery name="UpdateRes" datasource="#application.dsn#">
    UPDATE idx_res
    SET city = <cf_changecase case="titlecase" string="#qGetNames.city#"
    result="convCity">'#convCity#'
    WHERE idx_res.listing_num = #qGetNames.listing_num#
    </cfquery>
    </cfloop>

    adonis1976 Guest

  8. #7

    Default Re: Updating data in a column using it's own value

    This would probably be a bit clearer for you and future developers if you put
    the custom tag call outside the cfquery tag like this. Better yet, you could
    write title case as a <cffunction> and then say <cfset convCity =
    titlecase(qgetNames.city) />

    Either way, if you're making a lot of updates, I'd use <cfqueryparam>

    <cfloop query="qGetNames">
    <cf_changecase case="titlecase" string="#qGetNames.city#"
    result="convCity">
    <--- or <cfset convCity = titleCase(qgetNames.city) /> --->
    <cfquery name="UpdateRes" datasource="#application.dsn#">
    UPDATE idx_res
    SET city = <cfqueryparam value="#convCity#" cfsqltype="cf_sql_varchar" />
    WHERE idx_res.listing_num = <cfqueryparam value="#qGetNames.listing_num#"
    cfsqltype="cf_sql_integer" />

    </cfquery>
    </cfloop>


    shp.jc Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139