I am trying to insert my cursor result into table. Can anyone help?
SELECT DISTINCT
[Source System], [Business Transaction ID], [Contract Layer ID], Comment
INTO
#temp
FROM
dbo.FPSL_OverseasExceptions
ORDER BY
1, 2, 3
DECLARE commands CURSOR FOR
SELECT DISTINCT
txt = 'SELECT TOP 10 * FROM #temp WHERE Comment = ''' + Comment + ''' '
FROM #temp
DECLARE @cmd Varchar(MAX)
OPEN commands
FETCH NEXT FROM commands INTO @cmd
WHILE @@FETCH_STATUS = 0
BEGIN
EXEC(@cmd)
FETCH NEXT FROM commands INTO @cmd
END
CLOSE commands
DEALLOCATE commands
From this code I got several table result, I want to union them in one temp table so I can manipulate further. Can anyone help me?