title: Compare and test 00:00:00 time occurrence for scheduler
body: <p>For a scheduler - Start Time, End Time and NextOccurance Minutes or Hours are given.
  For that I have prepared logic as below</p>
  
  <pre><code>SET @StartTime = 17:00:00 
  SET @TEMP_TIME = StartTime --initially
  SET @ENDTIME = 23:59:59
  SET @RepeatTimeUnit = 1 --assume unit is hour 
  SET @RepeatTimeCount = 1 --to consider one hour
  </code></pre>
  
  <p>after execution of below loop, start time will be updated. But when I am running it between 11PM  and 12 AM it will take 00:00:00 as @NEXT_TIME in this case. SO, condition</p>
  
  <pre><code>if(@NEXT_TIME&gt;@CUR_TIME)
  </code></pre>
  
  <p>is always false and thus loop goes in infinite execution mode. But except this duration the same logic works well.</p>
  
  <p>How to handle this situation?
  Thanks for suggestion.</p>
  
  <pre><code>IF(@StartTime&lt;@CUR_TIME  AND  @ENDTIME&gt;@CUR_TIME)
  WHILE(1=1)
  BEGIN
  SET @NEXT_TIME=(SELECT CASE @RepeatTimeUnit WHEN 1 THEN DATEADD(HH,@RepeatTimeCount,@TEMP_TIME) WHEN 2 THEN DATEADD(MI,@RepeatTimeCount,@TEMP_TIME) END)
  SET @TEMP_TIME = @NEXT_TIME
  IF(@NEXT_TIME&gt;@CUR_TIME) BREAK
  else CONTINUE
  END
  SET @StartTime=@NEXT_TIME
  </code></pre>