Subject | RE: [firebird-support] toggle betweenn 0 and 1 |
---|---|
Author | Bogdan Mihalache |
Post date | 2014-04-02T07:26:28Z |
Update table set column = Mod(column+1,2) where id = :id
From: firebird-support@yahoogroups.com [mailto:firebird-support@yahoogroups.com] On Behalf Of Mark Rotteveel
Sent: Wednesday, April 2, 2014 10:16 AM
To: firebird-support@yahoogroups.com
Subject: Re: [firebird-support] toggle betweenn 0 and 1
On Wed, 2 Apr 2014 09:07:25 +0200, "checkmail" <check_mail@...>
wrote:
> is there a simple way to toggle between 0 and 1?Sure:
>
> Update table set column NOT column where id = :id?
>
> If column = 1 - then set to 0, else set to 1.
COLUMN = 1 - COLUMN (however this assumes that the column is NOT NULL and
always 1 or 0).
or with a simple CASE:
COLUMN = CASE COLUMN WHEN 1 THEN 0 ELSE 1 END
or a searched CASE:
COLUMN = CASE WHEN COLUMN = 1 THEN 0 ELSE 1 END
Mark