List:General Discussion« Previous MessageNext Message »
From:mos Date:September 23 2004 6:31pm
Subject:Re: A query to swap the data in two fields
View as plain text  
At 10:04 AM 9/23/2004, you wrote:
>On Thu, 23 Sep 2004 11:03:08 +0100,  wrote:
>
> >Hi,
> >
> >I want to swap the data in two fields
> >
> >eg
> >  t1.beds to t1.beds2
> >and
> > t2.beds2 to t1.beds
> > do I need to store one of the fields temporarily?
>
>Hey chums you normally get me an answer in minutes, is my question too easy?
>zzapper (vim, cygwin, wiki & zsh)
>--

zzapper,
         Gee, have you paid your bill yet?<g>

The only thing I've been able to come up with is:

update table1 a, table1 b set a.beds1=b.beds2, a.beds2=b.beds1 where 
a.rcd_id=b.rcd_id

You need to create a transitory value for one of the variables and this is 
done by joining the table onto itself (the "b" table won't get updated as 
table "a" gets updated). This solution should work on any column type.

There is probably a faster more efficient way of doing it (without a table 
join), but only if we knew what the column types were. If they were String 
then perhaps subscripting out the strings would be possible.

Mike

P.S. Now about your bill... :)  

Thread
A query to swap the data in two fieldszzapper23 Sep
  • Re: A query to swap the data in two fieldszzapper23 Sep
Re: A query to swap the data in two fieldsmos23 Sep
  • Re: A query to swap the data in two fieldszzapper23 Sep
Re: A query to swap the data in two fieldsBill Easton24 Sep