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 2005 Forums
 Transact-SQL (2005)
 How to write an update statement that uses the TOP

Author  Topic 

pras2007
Posting Yak Master

216 Posts

Posted - 2009-06-09 : 21:37:46
Hello All,

I want to update the first record order by the newest record. The below SQL is what I wrote which was giving me this error: Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'order'.

Query
UPDATE TOP (1) edge_etl_batch
SET Audit_Ind = 1
order by BatchDate DESC

Please advice. Thanks.

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-06-10 : 00:55:21
try like this

update t
set Audit_Ind = 1
from
(
select top 1 Audit_Ind from edge_etl_batch order by BatchDate desc )t

select * from edge_etl_batch
Go to Top of Page
   

- Advertisement -