Sqlserver
 SQL >> Database >  >> RDS >> Sqlserver

Restituire COUNT dinamico tramite OUTPUT

Modifica la variabile in NVARCHAR e restituisci il count tramite parametro OUTPUT:

SET @MySQL = 'SELECT @recordCount = COUNT(2) FROM ' + @MyTable + ' WHERE ' + @MyWhere;
EXEC sp_execute @MySQL, N'@recordCount INT OUTPUT', @recordCount OUTPUT;

Attenzione alla SQL injection.