In Sql Server 2000 and 2005 I am running a select statement in a while loop. JFYI, this select statement is connecting to many linked servers and getting some values.
IF there is any error, i want it should still execute next statement in the loop (similar to continue statement in c#)
Example:-
while @rowcount < 10
begin
set @sql = 'select * from <Remotemachine>.db1.dbo.table1'
exec sp_executesql @sql
set @rowcount = @rowcount +1
End
Start here: http://www.sommarskog.se/error_handling_2005.html
Keep in mind that some errors are session and even batch terminators and you can’t trap those
The link I gave you(and the 2 links on that page) should give you enough information on how to handle this
BTW, unless it is a non trapable error it will continue executing
run this
Here is the output
Here is how you can use
TRY CATCHto trap this