Stored Procedure Syntax

  • Thread starter Thread starter Joe
  • Start date Start date
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
 
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
 
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
 
Back
Top