You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by "sarah.kho" <sa...@gmail.com> on 2009/08/08 08:52:03 UTC

how I can swap content of two fields in one table?

Hi
Is there an easy way to swap content of two fields (sn and ssn) in a table
with hundreds of rows?
Thanks
-- 
View this message in context: http://www.nabble.com/how-I-can-swap-content-of-two-fields-in-one-table--tp24875562p24875562.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.


Re: how I can swap content of two fields in one table?

Posted by "sarah.kho" <sa...@gmail.com>.
Than you Knut,
It worked charming.

Thanks.

Knut Anders Hatlen wrote:
> 
> "sarah.kho" <sa...@gmail.com> writes:
> 
>> Hi
>> Is there an easy way to swap content of two fields (sn and ssn) in a
>> table
>> with hundreds of rows?
> 
> An update statement with "SET SN=SSN, SNN=SN" should do the trick. See
> the example below.
> 
> ij> select * from t;
> X   |Y   
> ---------
> x1  |y1  
> x2  |y2  
> x3  |y3  
> 
> 3 rows selected
> ij> update t set x=y, y=x;
> 3 rows inserted/updated/deleted
> ij> select * from t;
> X   |Y   
> ---------
> y1  |x1  
> y2  |x2  
> y3  |x3  
> 
> 3 rows selected
> 
> Hope this helps,
> 
> -- 
> Knut Anders
> 
> 

-- 
View this message in context: http://www.nabble.com/how-I-can-swap-content-of-two-fields-in-one-table--tp24875562p24927220.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.


Re: how I can swap content of two fields in one table?

Posted by Knut Anders Hatlen <Kn...@Sun.COM>.
"sarah.kho" <sa...@gmail.com> writes:

> Hi
> Is there an easy way to swap content of two fields (sn and ssn) in a table
> with hundreds of rows?

An update statement with "SET SN=SSN, SNN=SN" should do the trick. See
the example below.

ij> select * from t;
X   |Y   
---------
x1  |y1  
x2  |y2  
x3  |y3  

3 rows selected
ij> update t set x=y, y=x;
3 rows inserted/updated/deleted
ij> select * from t;
X   |Y   
---------
y1  |x1  
y2  |x2  
y3  |x3  

3 rows selected

Hope this helps,

-- 
Knut Anders