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
 General SQL Server Forums
 New to SQL Server Programming
 send Table name to procedure as a parameter

Author  Topic 

pooya1072
Starting Member

13 Posts

Posted - 2013-03-17 : 17:09:46
hi
i create a procedure in my database.this SP select all rows from a table :
CREATE PROCEDURE FillTable
AS
BEGIN
select * from [dbo].[TableName]
END

now ,i want to send the name of table as a parameter to SP . then this name (parameter) use in Select command .
how can i do it with this way or any way you know?

robvolk
Most Valuable Yak

15732 Posts

Posted - 2013-03-17 : 17:37:43
If you're changing the table you're selecting there's no real point in using a stored procedure. You'd have to use dynamic SQL, unless you have a limited number of tables, in which case you could use IF statements in a procedure.
Go to Top of Page

pooya1072
Starting Member

13 Posts

Posted - 2013-03-17 : 17:53:51
ok...thanks
Go to Top of Page
   

- Advertisement -