dbTalk Databases Forums  

update one colum with other column value in same table using update table statement

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss update one colum with other column value in same table using update table statement in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Manikandan
 
Posts: n/a

Default update one colum with other column value in same table using update table statement - 06-14-2007 , 11:21 AM






Hi,
I have table with three columns as below
table name:exp
No(int) name(char) refno(int)

I have data as below
No name refno
1 a
2 b
3 c

I need to update the refno with no values I write a query as below

update exp set refno=(select no from exp)
when i run the query i got error as
Subquery returned more than 1 value. This is not permitted when the
subquery follows =, !=, <, <= , >, >= or when the subquery is used as
an expression.

I need to update one colum with other column value.
What is the correct query for this ?

Thanks,
Mani


Reply With Quote
  #2  
Old   
Manikandan
 
Posts: n/a

Default Re: update one colum with other column value in same table using update table statement - 06-14-2007 , 11:27 AM






On 14 Jun, 17:21, Manikandan <plmanikan... (AT) gmail (DOT) com> wrote:
Quote:
Hi,
I have table with three columns as below
table name:exp
No(int) name(char) refno(int)

I have data as below
No name refno
1 a
2 b
3 c

I need to update the refno with no values I write a query as below

update exp set refno=(select no from exp)
when i run the query i got error as
Subquery returned more than 1 value. This is not permitted when the
subquery follows =, !=, <, <= , >, >= or when the subquery is used as
an expression.

I need to update one colum with other column value.
What is the correct query for this ?

Thanks,
Mani
Hi,
I used a query as below

update exp set refno=(select no from exp a where exp.NO =a.NO)

It works fine.
Is it correct?

Thanks,
Mani



Reply With Quote
  #3  
Old   
Plamen Ratchev
 
Posts: n/a

Default Re: update one colum with other column value in same table using update table statement - 06-14-2007 , 11:32 AM



If you simply need to update the refno column to the values in the no
column, then you can write your update statement as follows:

UPDATE exp
SET refno = no

Note that this query does not have a WHERE clause and will update all rows.

HTH,

Plamen Ratchev
http://www.SQLStudio.com



Reply With Quote
  #4  
Old   
Plamen Ratchev
 
Posts: n/a

Default Re: update one colum with other column value in same table using update table statement - 06-14-2007 , 11:36 AM



Yes, the query is correct, but it does not make sense to use a subquery
here. See my other post for more simplified approach.

Plamen Ratchev
http://www.SQLStudio.com



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.