how to use select union and loop 1

how to use select union and loop

CREATE TABLE #Temp
(
  
)

 DECLARE @position INT
 SET @position = -1

 WHILE(@position < 1)
 BEGIN

    INSERT INTO #Temp ()
    SELECT * FROM mytable

    SET @position = @position + 1

 END

 SELECT * FROM #Temp

Here is what the above code is Doing:
1. Create a temporary table with the same columns as the table you want to duplicate.
2. Declare a variable to keep track of the number of times you want to duplicate the table.
3. While the variable is less than the number of times you want to duplicate the table, insert the data from the table into the temporary table.
4. Increment the variable by 1.
5. Select the data from the temporary table.

Similar Posts