Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 table name as input variable?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-03-06 : 08:57:59
Rishabh writes "hello there,

I am facing a problem in creating a stored procedure.
I want to use the table name as input variable. But i am getting nothing except an error which reads:

Incorrect syntax near the keyword 'table'.
and
Must declare the variable '@table'.

I am giving you the code which I am using.

create proc sp_try
@table table
as
set nocount on
select * from @table
--print @s
go

Can anybody help me out.

regards
RISHABH GUPTA"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-03-06 : 09:02:26
You should make use of Dynamic SQL although passing object names as parameters not advisible

EXEC('select * from '+@table)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -