SQL if then语句

时间:2016-02-08 17:52:38

标签: sql

retry:
exec xxxxxxxxx

if @csvfilecount < 16
   begin
      waitfor delay '00:05:00'
      goto retry
   end
else
   begin
      send email
   end

我喜欢使用go重试2次尝试然后去发送电子邮件。 不知道怎么做。请帮忙。感谢

1 个答案:

答案 0 :(得分:0)

你可以使用带有计数器的while循环吗?

declare @counter as int
set @counter = 0

while @counter <= 2
begin
   @counter = @counter + 1
   -- your code here
   -- update @csvfilecount
   if @csvfilecount < 16
   begin
       waitfor delay '00:05:00'         
   end
   else
   begin
      send email
      -- do you want to BREAK here?
   end
end