I have followed the first answer found at this link: How to get sp_executesql result into a variable?
Declare @Num int;
Declare @DB_Name nvarchar(50);
Set @DB_Name = 'Database';
Declare @query nvarchar(100);
DECLARE @parm nvarchar(100);
Select @query = N'Select COUNT(Field) From ' + @DB_Name + '.dbo.Table';
Select @parm = N'@Num int OUT';
EXEC sp_executesql @query, @parm, @Num = @Num OUT;
Select @Num;
The output from the Exec statement provides me with the proper result in the Results Window, however, the last "Select @Num" statement returns NULL.
I need to use the value of the @Num Variable in the rest of my code.
Am I missing something?
Joseph