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)
 How to pass the name of a table to a stored procedure?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-06-28 : 09:05:46
Edika writes "I need to pass the name of a table to a stored procedure that must execute an update/Insert on that table. (SQL 7 sp3). I've try to declare a variable in the SP like @tablename as char and as sysname but on the syntax check return an error.

the sp is something like this:
CREATE procedure agg_dfondi
@tablename char,
@nvalue int,
@ndate smalldatetime,
as
if (select count(nvalue) from @tablename where ndate=@ndate)=0
begin
insert into @tablename (nvalue, ndate) values (@nvalue, @ndate)
end
else
begin
update @tablename set nvalue=@nvalue, ndate=@ndate
end

if a declare the @tablename as sysname it rreturn the same error, so there is a way to pass the table name to thi SP?"
   

- Advertisement -