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
Rushal AroraPosted Mar 12, 2013, 10:26 AM
Jignesh TrivediPosted Mar 12, 2013, 5:55 AM
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 AroraPosted Mar 12, 2013, 3:23 AM
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
Rushal AroraPosted Mar 12, 2013, 2:56 AM
Jignesh TrivediPosted Mar 11, 2013, 11:59 PM
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.
brunda kPosted Mar 11, 2013, 8:13 PM
constraint of environment
Rushal AroraPosted Mar 11, 2013, 2:10 PM
brunda kPosted Mar 11, 2013, 1:27 PM
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