There were some while loops in a procedure and I want to remove them / replace with temp tables or any other ( not cursor) .
Below I have created a dummy syntax, I have to populate the TEMP_TABLE table based on some calculations. Please share any better option to do the same:
SET @J = 0
SET @DIFFERENCE = 10
SET @INCREMENT = 2
WHILE (@J < @DIFFERENCE)
BEGIN
SET @TO_DATE = (SELECT DATEADD(D, @INCREMENT, @TO_DATE))
IF (@TO_DATE <= GETDATE())
INSERT INTO TEMP_TABLE
VALUES(@J, @TO_DATE)
SET @J = @J + @INCREMENT
END
INSERT INTO ... SELECT ... FROM (tally) ... WHERE (loop condition)