Inserting record count into a variable using variable table name

Inserting record count into a variable using variable table name

 

  

Hi,

I have the following declared:

DECLARE @tableName varchar(20),
@record_count INT

set @tableName='EMPLOYEES'

I would like to something like this:

select @record_count = count(*) from @tableName

But I get the following error:
Incorrect syntax near '@table_name'.

I think it is something easy, but I rather seek your assitance instead of
spending much time figuring out (LazyDBA).

Thank you much.

Sang Nahm
MS Sql Server LazyDBA home page