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 |
|
BeamBrain
Starting Member
10 Posts |
Posted - 2009-05-19 : 06:48:35
|
| This is probably a daft question, but is it possible to pass an entire select statement into a stored procedure.reason i ask is beacuse i have a number of queries in dynamic sql which i want to convert to sp's. However by definition dynamic sql can be SELECT *from t_tableOR SELECT *from t_tablewhere ...and ....and ...which means i have to define multiple sp's ??so can i do exec sp_name ('SELECT * FROM t_table WHERE .....') |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2009-05-19 : 07:49:09
|
quote: This is probably a daft question, but is it possible to pass an entire select statement into a stored procedure
Not a daft question, but definitely a daft usage. You'd completely negate the purpose of a stored procedure with this approach.Can you explain in more detail what you're trying to accomplish? I imagine you have a dynamic WHERE clause, varying criteria or some such. |
 |
|
|
BeamBrain
Starting Member
10 Posts |
Posted - 2009-05-19 : 08:09:04
|
| Yes exactly, i have a dynamic where clause. So depending on user form input i could haveselect *from tableORselect *from tablewhere dep = '06'orselect *from tablewhere dep = '06'and type = 1orselect *from tablewhere type = 1etc.etc. there are many many variations....i discovered i could do this...CREATE PROCEDURE getRecords ( @DymanicSQL varchar(100) ) ASDECLARE @SQLStatement varchar(2000)SELECT @SQLStatement = @DymanicSQLEXEC(@SQLStatement)exec getRecords "SELECT whatever i want"but from what you are syaing this is pointless ?? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-05-19 : 11:06:46
|
cant you just use conditional logic in where likeselect *from tablewhere (dep = '06' or condition)and (type = 1 or condition) |
 |
|
|
|
|
|