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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2001-11-26 : 09:43:10
|
| Biddu writes "Hi, Can I pass SQL query as a parameter to a stored procedure. Please let me know.I would like to pass SQL query into the parameter "@strarr" in the stored procedure shown below.-----------------------------------create proc test @strarr varchar(100)asBegin--DECLARE Ofr_cursor CURSOR STATIC FOR select * from tbl_Cntct_Role DECLARE Ofr_cursor CURSOR STATIC FOR + @strarr End----------------------------Thanks in advance.Biddu." |
|
|
royv
Constraint Violating Yak Guru
455 Posts |
Posted - 2001-11-26 : 09:52:18
|
| Yes you can do this, however 2 things:1.) I do not recommend this2.) The way you are attempting to use this is incorrect.The best way to do what you want to accomplish is to use dynamic sql and pass in parameters that will affect your where clause. However, yes you can pass in the sql as you have shown below, and to execute it you would dynamically generate a string with the cursor sql in it like so:set @dynamicSQL='DECLARE Ofr_cursor CURSOR STATIC FOR ' + @starrexec (@dyanmicSQL)*************************Just trying to get things done |
 |
|
|
|
|
|