Upon executing the following code I get this error: ------------------------------------------------- Msg 137, Level 15, State 1, Line 1 Must declare the scalar variable "@MyCount". -------------------------------------------------
I need to store the count in a variable dynamically to genrate complicated report. Any sugestions ?
Thank you
DECLARE @MyCount INT DECLARE @MyTable VARCHAR(10) DECLARE @SqlCmd NVARCHAR(500)
SET @Mytable = 'test'
SET @SqlCmd = 'SELECT @MyCount =COUNT(*) FROM ' + @MyTable