DECLARE @sql NVARCHAR(MAX) = 'SET @count = ( SELECT * FROM sys.objects )'

DECLARE @count INT
EXEC sp_executeSQL @sql, N'@count INT OUTPUT', @count OUTPUT

PRINT @count

Notes

The statement and parameter must be an NVARCHAR or NCHAR.

In this case @sql is the statement parameter.

In this case N'@count INT OUTPUT' is the parameter. Remember N is the NVARCHAR attribute.

Copyright © 2024 delaney. All rights reserved.