How to implement a do-while loop in tsql

This is effectively a Do-While loop:

WHILE (1=1)
BEGIN
  
  -- Do stuff...

  IF (some_condition is true)
     BREAK;

END

But as @Joel Coehoorn noted, always try to use a set based approach first. I would only resort to a loop if I can’t think of a way to solve using set operations.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)