I have this SQL Script:
DECLARE @Loop INT
SET @Loop = 1
DECLARE @Result table([1] int, [2] int,[3] int,[4] int,[5]);
WHILE (@Loop <=5)
BEGIN
INSERT INTO @Result(@Loop)
SELECT Id FROM Students WHERE Id=@Loop
SET @Loop= @Loop+ 1
END
I got an error in this line:
INSERT INTO @Result(@Loop)
Is it possible to use this way to insert data into column names using loop ? I mean dynamicaly
Thanks