You can use the EXEC method. Here is a short example:
CREATE Procedure spTest
(
@tablename nvarchar(25),
@MyID int
)
AS
Declare @mySQLStatement varchar(100)
Select @mySQLStatement = 'SELECT * FROM ' + @tablename + ' WHERE ID = ' +
Cast (@MyID as varchar)
Exec (@mySQLStatement)
This statement will dynamically select content from a table based on the
parameter @tablename.
HtH
Imar
At 10:42 AM 2/8/2001 -0500, you wrote:
>Hello to all!
>
>I would like to know how (of if it's possible) to pass a table or view
>name into a PROC. Here's the example I am working on...
>
>Create Proc AddCount
> @TableName
>AS
>Update @TableName set count =3D count + 1
>
>
>The above statement will parse with [ ] put around the variable in the
>update statement, but won't execute, giving an unresolved object error.
>Of course, it works to use the variable in the where clause, but I've
>not found a way, nor documentation, on how to use a variable as the
>primary object in the sql statement. Is it possible?
>
>Thanks in advance for any advice!
>
>David Oakland