How about this:
DECLARE @SQL_STRING NVARCHAR(MAX), @rows INT
SET @SQL_STRING = 'Your SQL Code Here'
EXEC sp_executesql @SQL_STRING
SELECT @rows = @@ROWCOUNT
PRINT '@rows = ' + CAST(@rows AS VARCHAR(10))
Best regards,
Cosmog Hong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".