Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

SQL Server:ottieni gli ID delle righe sommate

Questo dovrebbe funzionare:

 select sum(amount) sum,
        (
        STUFF((
            SELECT  DISTINCT ',' + CAST(a.id AS VARCHAR(100))
            FROM    t_vouchers a
            WHERE   a.isactive = 1
            FOR XML PATH('')
            ),1,1,'')
        ) ids
 from t_vouchers
 where isactive = 1

Ecco un SQL Fiddle