Torna al Thread
declare @campo nvarchar(50)
declare @str nvarchar(max)
set @campo = 'id'
set @str = 'select dettaglio.id, sum(dettaglio.valore), count(dettaglio.id) from dettaglio where dettaglio.' + @campo + ' = @id group by dettaglio'
declare cur cursor for @str into ...
...