Updating a field

Updating a field

am 16.02.2007 16:30:26 von Brian

Hi there

I'm sure this can be done but not sure of the MSQL code

I want to run an update statement on a field where it adds
X to want ever is already in the field?

e.g.
field = 10
Add = 5
update field add 5 to field so field now = 15
but if field was null then field now = 5

Brian



------------------------------------------------------------ --------------------
I am using the free version of SPAMfighter for private users.
It has removed 2353 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!

Re: Updating a field

am 16.02.2007 16:45:42 von Rik

On Fri, 16 Feb 2007 16:30:26 +0100, Brian =
=

wrote:

> Hi there
>
> I'm sure this can be done but not sure of the MSQL code
>
> I want to run an update statement on a field where it adds
> X to want ever is already in the field?
>
> e.g.
> field =3D 10
> Add =3D 5
> update field add 5 to field so field now =3D 15
> but if field was null then field now =3D 5
>
> Brian

UPDATE `table` SET `field` =3D `field` + 5

-- =

Rik Wasmus

Re: Updating a field

am 16.02.2007 16:46:14 von Captain Paralytic

On 16 Feb, 15:30, "Brian" wrote:
> Hi there
>
> I'm sure this can be done but not sure of the MSQL code
>
> I want to run an update statement on a field where it adds
> X to want ever is already in the field?
>
> e.g.
> field =3D 10
> Add =3D 5
> update field add 5 to field so field now =3D 15
> but if field was null then field now =3D 5
>
> Brian
>
> ------------------------------------------------------------ -------------=
--=AD-----
> I am using the free version of SPAMfighter for private users.
> It has removed 2353 spam emails to date.
> Paying users do not have this message in their emails.
> Try SPAMfighter for free now!

UPDATE table SET field =3D IFNULL(field,0) + 5

Re: Updating a field

am 16.02.2007 16:47:40 von Captain Paralytic

On 16 Feb, 15:45, Rik wrote:
> On Fri, 16 Feb 2007 16:30:26 +0100, Brian
> wrote:
>
> > Hi there
>
> > I'm sure this can be done but not sure of the MSQL code
>
> > I want to run an update statement on a field where it adds
> > X to want ever is already in the field?
>
> > e.g.
> > field = 10
> > Add = 5
> > update field add 5 to field so field now = 15
> > but if field was null then field now = 5
>
> > Brian
>
> UPDATE `table` SET `field` = `field` + 5
>
> --
> Rik Wasmus

But that doesn't work if the field is currently NULL. See my post for
the solution.

Re: Updating a field

am 16.02.2007 17:12:24 von Brian

> Hi there
>
> I'm sure this can be done but not sure of the MSQL code
>
> I want to run an update statement on a field where it adds
> X to want ever is already in the field?
>
> e.g.
> field = 10
> Add = 5
> update field add 5 to field so field now = 15
> but if field was null then field now = 5
>
> Brian
>
> UPDATE table SET field = IFNULL(field,0) + 5

WOW, that's easier than I thought, thanks Captain Paralytic


------------------------------------------------------------ --------------------
I am using the free version of SPAMfighter for private users.
It has removed 2355 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!

Re: Updating a field

am 16.02.2007 19:12:45 von unknown

Post removed (X-No-Archive: yes)