Tom,
When I ran the code as is, I get the following error:
Invalid object name '#tom'.
After I changed #tom to ##tom (glocal temporary table), it worked fine.
Thank you all so much for your reponses.
With much gratitude.
Sang
-----Original Message-----
From: thomas.[Email Address Removed] [mailto:thomas.[Email Address Removed] Tuesday, September 17, 2002 3:05 PM
To: sang.[Email Address Removed] [Email Address Removed] RE: Inserting record count into a variable using variable table
n ame
Sang,
Sorry for the delay, I didn't have much time to play with it.
It's kind of roundabout but you might try something like this:
declare @tn varchar(20), @ls nvarchar(200), @rc int
set @tn='sysobjects'
exec ( 'select count(*) as rc into #tom from ' + @tn)
select @rc = rc from #tom
select @rc
. . . Tom
On 09/17/2002 10:43:47 AM sang.nahm wrote:
> Simon,
>
> Thanks.
>
> I am still getting the following message:
>
> Must declare the variable '@table_name'.
>
> Here are the exact codes:
>
> declare @table_name varchar(20),
> @count INT
>
> set @table_name='ORD_TABLES'
> set @count = (select count(*) from @table_name)
>
> Sang Nahm
>
> -----Original Message-----
> From: Simon Holdsworth [mailto:Simon.[Email Address Removed] Sent: Tuesday, September 17, 2002 10:32 AM
> To: 'sang.[Email Address Removed] LazyDBA.com Discussion
> Subject: RE: Inserting record count into a variable using variable table
> n ame
>
>
> set @record_count = (select count(*) from @tableName)
>
>
> -----Original Message-----
> From: sang.[Email Address Removed] [mailto:sang.[Email Address Removed] Sent: Tuesday, September 17, 2002 8:29 AM
> To: LazyDBA.com Discussion
> Subject: 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
>
-----------------------------------------------------------------
Visit our Internet site at http://www.reuters.com
Any views expressed in this message are those of the individual
sender, except where the sender specifically states them to be
the views of Reuters Ltd.
MS Sql Server LazyDBA home page