Advertisement

10.21.2005 at 09:06AM PDT, ID: 21603280
[x]
Attachment Details

Must declare the table variable "@table_name".

Asked by EchoBinary in MS SQL Server

Tags: , , ,

I get the following error:
Msg 1087, Level 15, State 2, Line 16
Must declare the table variable "@table_name".

In the following code:
=============================================
DECLARE c CURSOR FOR
      SELECT table_name FROM vwAgency_tables WHERE aid = @iAid

OPEN c
FETCH next FROM c INTO @table_name
      WHILE @@fetch_status = 0
            BEGIN
                SELECT @iHitCount = COUNT(*) FROM @table_name WHERE TIN LIKE '%'+@sTIN+'%'   --      <---------------
                    FETCH next FROM c INTO @table_name
            END
CLOSE c
DEALLOCATE c
=============================================

Is there any way to do this without using EXEC on a varchar?

The end result is that id like to keep a running total count of matches from several tables (those tables are only known at runtime)Start Free Trial
[+][-]10.21.2005 at 09:08AM PDT, ID: 15133507

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.21.2005 at 09:09AM PDT, ID: 15133513

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]10.21.2005 at 11:39AM PDT, ID: 15134590

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.21.2005 at 01:47PM PDT, ID: 15135547

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.21.2005 at 02:08PM PDT, ID: 15135659

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.21.2005 at 02:53PM PDT, ID: 15135883

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.21.2005 at 03:24PM PDT, ID: 15136043

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Tags: declare, table, variable, must
Sign Up Now!
Solution Provided By: ala_frosty
Participating Experts: 3
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32