I am attempting to build a query on the fly that will set a variable. How would I do this?
Here is what I have so far
DECLARE @SQL as NVARCHAR(500)
DECLARE @ParmDefinition NVARCHAR(500)
set @SQL = 'set @maxRowCount = (select count(*) from Test)'
SET @ParmDefinition = N'@maxRowCount int';
EXECUTE sp_executesql @SQL, @ParmDefinition
When I run this I get the following error
Msg 8178, Level 16, State 1, Line 1
The parameterized query '(@maxRowCount int)set @maxRowCount = (select count(*) from docto' expects the parameter '@maxRowCount', which was not supplied.
I am trying to get @maxRowCount to be set to the total row count of the Test table