DECLARE @tags varchar(200) DECLARE @K int SET @K=1 DECLARE MyCursor CURSOR FOR SELECT columns FROM table OPEN MyCursor -- read the first record FETCH MyCursor INTO @tags -- loop WHILE @@fetch_Status = 0 BEGIN INSERT INTO table2 (id, new_tags) VALUES (@K, @tags); SET @K = @K + 1; -- read next record FETCH MyCursor INTO @tags END CLOSE myCursor DEALLOCATE myCursor
Source : http://sqlpro.developpez.com/cours/sqlserver/transactsql/