[dba-SQLServer] Get a count inside of a stored procedure

jwcolby jwcolby at colbyconsulting.com
Wed Jul 25 19:06:09 CDT 2012

In a stored procedure I need to get a count of the records in a table where the table name is passed 
in to the SP.

I tried:

DECLARE @RecordCnt int

	SELECT @RecordCnt = Count([Column 0]) FROM @TblName

Where @TblName is the passed in table name.

This fails telling me that I have to declare a table variable @TblName

Is there a simple way to do what I am trying to do?
John W. Colby
Colby Consulting

Reality is what refuses to go away
when you do not believe in it

More information about the dba-SQLServer mailing list