Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Need help on update query

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2007-02-06 : 08:56:05
chinmayee writes "Hi,

I want to copy a few column values from 1 row to the newly added row. So I have written update query like

update steps set label=(select label from steps
where id = 1),
instruction = (select instruction from steps
where id = 1),
image = (select image from steps
where id = 1),
html= (select html from steps
where id = 1),
where id = (select max(id) from steps)

I'm not sure about the performance of this query. Is this only method to perform copy?

Can anyone help me?

Thanks in advance."

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-06 : 09:01:17
use INNER JOIN & table alias


update u
set label = s.label,
instruction = s.instruction,
. . .
from steps u inner join steps s
on s.id = 1
and u.id = (select max(id) from steps)



KH

Go to Top of Page
   

- Advertisement -