Alternative of top class for delete and update query in sql 2000 is @@Rowcount & in Sql 2005 or 2008 we have
delete top(1) from emp where salary = 13000
update top(1) emp set salary = 1000 where salary = 13000
Above two queries can be executed only in Sql 2005 or 2008 but if we need to execute it in sql 2000 we do it with the help of @@rowcount .
Please tell me the above two query using @@rowcount.
Loading

brunda kRank #3,804 · 389 reputationPosted Mar 11, 2013, 9:27 AM EDT
declare @myrowcount int
delete top(1) from emp where salary = 13000
SET @myrowcount=@@rowcount
if @myrowcount>0
Begin
update top(1) emp set salary = 1000 where salary = 13000
End
End
Rushal Arora191 reputationPosted Mar 11, 2013, 10:10 AM EDT
brunda kRank #3,804 · 389 reputationPosted Mar 11, 2013, 4:13 PM EDT
constraint of environment
Jignesh TrivediRank #16 · 50.3K reputationPosted Mar 11, 2013, 7:59 PM EDT
As per my knowledge you can also use top key word with update and delete statement in SQL server 2000.
Please refer
http://msdn.microsoft.com/en-us/library/aa260662%28v=sql.80%29.aspx
hope this will help you.
Rushal Arora191 reputationPosted Mar 11, 2013, 10:56 PM EDT
Rushal Arora191 reputationPosted Mar 11, 2013, 11:23 PM EDT
Thanks 4 replying but would like to tell u that you can only use 'top' class with select in sql server 2000 not with update & delete directly and in the link u suggested top class is used with select & hence used indirectly with update . Aneways apart from this please tell me how to use @@rowcount for the update & delete query for the below (Dont use top class):
delete top(1) from emp where salary = 13000
update top(1) emp set salary = 1000 where salary = 13000
Jignesh TrivediRank #16 · 50.3K reputationPosted Mar 12, 2013, 1:55 AM EDT
you can also use sub query or join query instead of @@RowCount.
update table1
set field1=1
where id in (select top 1 id from table1 where field1=0)
OR
UPDATE table1
SET Filed1 = 1
FROM (SELECT TOP 1 FROM table1 where Id = 0) AS t1
WHERE table1.id = t1.id
generally @@rowcount Returns the number of rows affected by the last statement.
hope this will help you.
Rushal Arora191 reputationPosted Mar 12, 2013, 6:26 AM EDT