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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 send Table name to procedure as a parameter
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

pooya1072
Starting Member

13 Posts

Posted - 03/17/2013 :  17:09:46  Show Profile  Reply with Quote
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

USA
15732 Posts

Posted - 03/17/2013 :  17:37:43  Show Profile  Visit robvolk's Homepage  Reply with Quote
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 - 03/17/2013 :  17:53:51  Show Profile  Reply with Quote
ok...thanks
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000