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
Semoga membantu. Di DECLARE CURSOR, Anda perlu mengubah "ColumnName" dan "TableName" menjadi kolom/tabel aktual yang Anda kueri.