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

update add to column

Guest
May 22, 2006 May 22, 2006

Copy link to clipboard

Copied

hi i have a number column called "man" i also have a update query which i need to add to this column

set Man = '100'

this changes the value to 100

what i need is to add 100 to the number already in the column

not sure how to do this ?

TOPICS
Advanced techniques

Views

262

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
Participant ,
May 22, 2006 May 22, 2006

Copy link to clipboard

Copied

<CFSET Man = 100>

get the value of 'man' first:

<CFQUERY NAME="getValueofMan" DATASOURCE="#theDSN#">
SELECT man FROM theTable WHERE id = #theUniqueID#
</CFQUERY>

<CFIF getValueofMan.recordcount NEQ 0>
<CFSET Man = Man + getValueofMan.man>
</CFIF>

<CFQUERY NAME="updateValueofMan" DATASOURCE="#theDSN#">
UPDATE theTable set man = #Man# WHERE id = #theUniqueID#
</CFQUERY>

Jam

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
LEGEND ,
May 22, 2006 May 22, 2006

Copy link to clipboard

Copied

LATEST
This is the easiest way and will work as long as man is not null to start with.

update thetable
set man = man + 100
where whatever

If you want to treat nulls as zero, and your db supports this syntax, this should work

update thetable
set man = coalesce(man, 0) + 100
where whatever

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