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 |
|
snaso
Starting Member
21 Posts |
Posted - 2005-02-01 : 06:37:17
|
Hi All.I was facing the problem of putting an IF in a Stored Procedure.I think I've found a nice solution, I would like to have your comments.I know that putting IF inside SP it is not efficient because the execution plan changes depending on the "IF variable"'s value - that is known at run-time.So I've thought to solve this efficiency problem by adding a "where" condition in the T-SQL I have to execute in the SP in place of an IF().Here follows an example:if(@var1 = 'yes')begin update table1 set description = 'OK' where code = @var3end This can be replaced with:update table1 set description = 'OK' where code = @var3 and @var1 = 'yes' What do you think about this solution? I thank you all in forward for any comment,Regards, snaso.-snaso. |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2005-02-01 : 06:52:31
|
| I like it. To get rid of IF condition... a nice trick. |
 |
|
|
|
|
|