Shilohcity
Technical User
Hi there
I am trying to do the following:
SET @cnt = (SELECT COUNT (*) FROM @dynamicTableName)
This keeps on erroring on the use of a local variable for the table name. If I replace the variable with the hard coded table name it works fine.
I know how to do this as:
SET @SQLString = "SELECT COUNT (*) FROM " + @dynamicTableName
EXEC(@SQLString)
but I need the return value as a variable so I can work with it.
Any suggestions or ideas greatfully received.
Cheers
Justin. "Creativity is the ability to introduce order into the randomness of nature." Eric Hoffer
Visit me at
I am trying to do the following:
SET @cnt = (SELECT COUNT (*) FROM @dynamicTableName)
This keeps on erroring on the use of a local variable for the table name. If I replace the variable with the hard coded table name it works fine.
I know how to do this as:
SET @SQLString = "SELECT COUNT (*) FROM " + @dynamicTableName
EXEC(@SQLString)
but I need the return value as a variable so I can work with it.
Any suggestions or ideas greatfully received.
Cheers
Justin. "Creativity is the ability to introduce order into the randomness of nature." Eric Hoffer
Visit me at