Subject Re: [firebird-support] Exchange two column values in a single statement...
Author Martijn Tonies
> ...without a temporary field ;)
>
> Here's how I did it:
>
> create table t1 ( a integer, b integer );
> insert into t1 (a,b) values (1,2);
> insert into t1 (a,b) values (3,4);
> insert into t1 (a,b) values (5,6);
> insert into t1 (a,b) values (7,8);
> select * from t1;
>
> And now the magic:
>
> update t1 set a = a+b, b = a-b, a = a-b;
> select * from t1;
>
>
> P.S. Kids, don't try this at home, or on important data.

Pitty it won't work on character data ;-)

Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Oracle &
MS SQL Server
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com