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)
 Stored Procedure

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-01-16 : 09:51:29
priya writes "I want to create a generic stored procedure which takes the table name as an
input parameter and queries it. So how to use the input variable in the INSERT statement?"

Nazim
A custom title

1408 Posts

Posted - 2002-01-16 : 10:13:04
i would suggest you to go thru this Article's by Merkin on Dynamic Sql
http://www.sqlteam.com/item.asp?ItemID=4599
http://www.sqlteam.com/item.asp?ItemID=4619

this should do what you are looking for
create table query_res(@m varchar(255))
as
declare @mvar as varchar(600)

Set nocount on
select @mvar="select * from "+ @m
exec (@mvar)
Go

----------------------------------
"True love stories don't have endings."
Go to Top of Page
   

- Advertisement -