-- this won't work
CREATE PROCEDURE count_rows(@name NVARCHAR(50))
AS
SELECT COUNT(*) FROM @name
GO

-- this will
-- the dynamic SQL executes in the caller's context
CREATE PROCEDURE count_rows(@name NVARCHAR(50)
AS
EXECUTE('SELECT COUNT(*) FROM ' + @name)
GO

