question

haneesh avatar image
haneesh asked

i want create a procedure but the parameters is need to be generate automatically accord to the rows in another table

i want create a procedure but the parameters is need to be generate automatically accord to the rows in another table
sql-server-2005
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Grant Fritchey avatar image
Grant Fritchey answered
You can't create a procedure with dynamic parameters. A stored procedure's parameters are defined at the moment you create it and they can't change except by recreating the procedure. From the sounds of things, you need a dynamic t-sql statement. In order to use parameters with dynamic t-sql you're best bet is to use sp_executesql. [Here's a link to the documentation on it][1]. This would allow you to build a t-sql statement with parameters, defined on the fly, and execute it. This way, you have a chance at some plan reuse when running your statements. [1]: http://msdn.microsoft.com/en-us/library/ms188001.aspx
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.