Stored Procedure Syntax

J

Joe

Hello All:
I would like to pass a variable to a stored procedure,
that would be a piece of a concatenated string to make up
the table name. The code I have so far is below. The
problem I'm having is in created the concatenated string
(tbl??Product??final) for the table name and adding it to
the SQL statement. Can this be done?

CREATE PROCEDURE product
(
@Product varchar(10),
@TestPlan varchar(30)
)
AS

SELECT * FROM tbl??Product??final
WHERE strTestPlan = @TestPlan
GO

Any help is appreciated.
Thanks,
Joe
 
V

Vadim Rapp

Hello Joe:
You wrote on Mon, 19 Jul 2004 06:46:56 -0700:

J> I would like to pass a variable to a stored procedure,
J> that would be a piece of a concatenated string to make up
J> the table name. The code I have so far is below. The
J> problem I'm having is in created the concatenated string
J> (tbl??Product??final) for the table name and adding it to
J> the SQL statement. Can this be done?

Bad most likely, it can't be done.

Good you can construct the query string and execute it directly, w/o
any stored procedure.

Vadim
 
V

Vadim Rapp

J> Hello All:
J> I would like to pass a variable to a stored procedure,
J> that would be a piece of a concatenated string to make up
J> the table name. The code I have so far is below. The
J> problem I'm having is in created the concatenated string
J> (tbl??Product??final) for the table name and adding it to
J> the SQL statement. Can this be done?

J> CREATE PROCEDURE product
J> (
J> @Product varchar(10),
J> @TestPlan varchar(30)
J> )
J> AS

J> SELECT * FROM tbl??Product??final
J> WHERE strTestPlan = @TestPlan
J> GO

I was wrong, sorry. The idea is:

alter procedure aaaa(@tbl varchar(50)) as

declare @s varchar(250)
set @s='select * from ' + @tbl
exec (@s)





Vadim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top