DECLARE @sSQL varchar(max),
@ColumnName CHAR(128)
DECLARE TableCursor CURSOR FOR
SELECT ColumnName FROM GroupTable
SET @sSQL = 'CREATE TABLE ##NewTempTable ('
OPEN TableCursor
FETCH NEXT FROM TableCursor INTO @ColumnName
WHILE @@FETCH_STATUS = 0
BEGIN
SET @sSQL = @sSQL + RTRIM(@ColumnName) + ' CHAR(10) ,'
FETCH NEXT FROM TableCursor INTO @ColumnName
END
CLOSE TableCursor
DEALLOCATE TableCursor
SET @sSQL = @sSQL + ')'
EXEC (@sSQL)
SELECT * FROM ##NewTempTable
Ik hoop dat dit helpt. In de DECLARE CURSOR moet u de "ColumnName" en "TableName" wijzigen in uw werkelijke kolom/tabel die u opvraagt.