sql While loop

Declare @Counter int
Set @Counter = 0
While @Counter < 10
Begin
	Select @Counter
	Set @Counter = (@Counter + 1)
	
	--optional logic to escape the While loop
	If (@Counter / 2) = 4
		Break
	Else
		Continue
End
Example of using a While loop within SQL.

Updated: Thursday 8th September 2011, 02:57am

There are 0 comments

Leave a comment of your own

Comments are currently closed.