Updating a field

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!
Brian [ Fr, 16 Februar 2007 16:30 ] [ ID #1631530 ]

Re: Updating a field

On Fri, 16 Feb 2007 16:30:26 +0100, Brian <djswirl [at] remove_me_yahoo.com> =
=

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
Rik [ Fr, 16 Februar 2007 16:45 ] [ ID #1631531 ]

Re: Updating a field

On 16 Feb, 15:30, "Brian" <djswirl [at] remove_me_yahoo.com> 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
Captain Paralytic [ Fr, 16 Februar 2007 16:46 ] [ ID #1631532 ]

Re: Updating a field

On 16 Feb, 15:45, Rik <luiheidsgoe... [at] hotmail.com> wrote:
> On Fri, 16 Feb 2007 16:30:26 +0100, Brian <djswirl [at] remove_me_yahoo.com>
> 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.
Captain Paralytic [ Fr, 16 Februar 2007 16:47 ] [ ID #1631533 ]

Re: Updating a field

> 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!
Brian [ Fr, 16 Februar 2007 17:12 ] [ ID #1631534 ]

Re: Updating a field

Post removed (X-No-Archive: yes)
Notifier Deamon [ Fr, 16 Februar 2007 19:12 ] [ ID #1631535 ]
PHP » alt.php.sql » Updating a field

Vorheriges Thema: FAQ... should we have one?
Nächstes Thema: renumbering fields