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

Valore restituito da exec(@sql)

Da un lato potresti usare sp_executesql:

exec sp_executesql N'select @rowcount=count(*) from anytable', 
                    N'@rowcount int output', @rowcount output;

D'altra parte potresti usare una tabella temporanea:

declare @result table ([rowcount] int);
insert into @result ([rowcount])
exec (N'select count(*) from anytable');
declare @rowcount int = (select top (1) [rowcount] from @result);