TSQL 中 while 循环中的 continue 语句?
在 Sql Server 2000 和 2005 中,我在 while 循环中运行 select 语句。 JFYI,这个 select 语句正在连接到许多链接服务器并获取一些值。
如果有任何错误,我希望它仍然应该执行循环中的下一条语句(类似于 c# 中的 continue 语句)
示例:-
while @rowcount < 10
begin
set @sql = 'select * from <Remotemachine>.db1.dbo.table1'
exec sp_executesql @sql
set @rowcount = @rowcount +1
End
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从这里开始: http://www.sommarskog.se/error_handling_2005.html
请记住,有些错误是会话甚至批处理终止符,您无法捕获这些错误
我给您的链接(以及该页面上的 2 个链接)应该为您提供有关如何处理此
顺便说一句的足够信息,除非它是不可捕获的错误,否则它将继续执行
run this
这是输出
这是如何使用
TRY CATCH
来捕获它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 CATCH
to trap this2005 年,您可以放入 try/catch。
In 2005 you can put in a try/catch.