DECLARE @Count INTEGER
DECLARE @nSQL NVARCHAR(1000)
SET @nSQL = 'SELECT @Count = COUNT(*) FROM ' + @tablename
EXECUTE sp_executesql @nSQL, N'@Count INTEGER OUT', @Count OUT
-- Now check @Count
Be extra careful with dynamic sql like this, as you open yourself up to sql injection. So make sure @tablename is sanitized.
One check to be safe would be something like this, by making sure the table exists using a parameterised query before attempting the dynamic query:
DECLARE @Count INTEGER
DECLARE @nSQL NVARCHAR(1000)
SET @nSQL = 'IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME=@TableName)
SELECT @Count = COUNT(*) FROM ' + @tablename + '
ELSE
SELECT @Count = -1'
EXECUTE sp_executesql @nSQL, N'@TableName NVARCHAR(128), @Count INTEGER OUT', @TableName, @Count OUT
If @Count then comes out at -1, you know it's because the tablename is invalid
Edit:
Reference to sp_executesql is here