• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Update one field from another in the same table

Explorer ,
Jun 13, 2006 Jun 13, 2006

Copy link to clipboard

Copied

How do I write a query that sets a field within a table to the value of another field from the same table?
TOPICS
Advanced techniques

Views

372

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 13, 2006 Jun 13, 2006

Copy link to clipboard

Copied

update table set field1 = field2 where field3 = 'blah';

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 13, 2006 Jun 13, 2006

Copy link to clipboard

Copied

Here's what I have now for my query:

<CFQUERY datasource="#application.dsn#">
UPDATE affiliate
SET last_contacted = #affiliate.originated#
</CFQUERY>

This produces the following error:

Element ORIGINATED is undefined in AFFILIATE.

It doesn't want to recognize a field within the table.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 13, 2006 Jun 13, 2006

Copy link to clipboard

Copied

You're not supposed to put ## around it. That makes Coldfusion look for a variable named "originated" inside a structure named "affiliate", which obviously isn't what you want to do.

In my query, I didn't have any hashes around field2.

Change your query to:
<CFQUERY datasource="#application.dsn#">
UPDATE affiliate
SET last_contacted = originated
</CFQUERY>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 13, 2006 Jun 13, 2006

Copy link to clipboard

Copied

LATEST
Thanks for your help

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation