Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
drmaves #1
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
-
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... -
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 ... -
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... -
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... -
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... -
adonis1976 #2
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
-
drmaves #3
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
-
Kronin555 #4
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
-
drmaves #5
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
-
adonis1976 #6
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
-
shp.jc #7
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



Reply With Quote

