user1203397 February 2016

SQL if then statement

retry:
exec xxxxxxxxx

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

I like to use go to retry for 2 try only and then go to send email. Not sure to how do this. Please help. Thanks

Answers


deweycooter February 2016

Can you use a while loop with a counter?

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

Post Status

Asked in February 2016
Viewed 2,838 times
Voted 5
Answered 1 times

Search




Leave an answer