while (1=1) -can be used to break a loop
It could be used in a situation where you plan to exit a WHILE loop using the BREAK command:
WHILE 1 = 1
BEGIN /* Loop till uniq auth code is found for the date */
SELECT @AuthCodeInt = DATEPART(millisecond, GETDATE())
+ ( DATEPART(second, GETDATE()) * 10 ) + ( DATEPART(minute,
GETDATE()) * 60
* 10 )
+ ( DATEPART(hour, GETDATE()) * 60 * 60 * 10 )
SELECT @AuthCode = RIGHT(CONVERT(CHAR(7), @AuthCodeInt + 1000000),
6)
IF NOT EXISTS ( SELECT 1
FROM PDXHPLogTable (NOLOCK)
WHERE DATEDIFF(Day, TranDate, GETDATE()) = 0
AND AuthCode = @AuthCode )
BREAK /* Uniq code made. Hence exit from the loop */
END
Comments
Post a Comment