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
Spero che questo aiuti. In DECLARE CURSOR, dovrai cambiare "ColumnName" e "TableName" nella colonna/tabella che stai interrogando.