Can I pass in a function name or datasource to a T-SQL function or stored procedure as parameter? So as to reuse the function or stored procedure. If possible can show me some examples?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes you can, it’s through an approach known as dynamic sql. The real question to answer now that you know that is should you. There are a lot of caveats and dangers to dynamic sql that you need to be aware of if you are going to use that approach.
There’s a whole lot of really good info out on the web that can give you more info. A good place to start is here. This has been a good guide on the web for some time.
http://www.sommarskog.se/dynamic_sql.html
This is also another good series to read up on.
http://www.mssqltips.com/sqlservertip/1160/execute-dynamic-sql-commands-in-sql-server/
To be clear dynamic sql has some very good uses… just be careful and wise.