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 |
jassie
Constraint Violating Yak Guru
332 Posts |
Posted - 2013-10-10 : 13:48:59
|
In t-sql 2008 r2, can you tell me what performs better from the following two options and why:1. If parameter value = '1' goto parm1 else of parameter value = '2' goto parm2 goto final parm1: <do something1> goto final parm2: <do something2> final:2. If parameter value = '1' <do something1> else of parameter value = '2' <do something2> |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-10 : 14:52:39
|
My preference is option 2. Using GOTO is very confusing compared to IF..THEN..ELSE so I prefer using thatAlso too many GOTO means control flow jumps from one point to other which will be very difficult to follow and maintain.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-10-10 : 16:31:52
|
In almost all cases, resources spent in evaluating the logic is trivial compared to the resources required to retrieve the data, sort it, and send it over the network. So it is not worth trying to optimize the code that implements the logic. You should do what is most readable and maintainable.So, for your own sake, and for the sake of posterity, stick with the second option.One thing to keep in mind, which you probably know already, is that if you have more than one statement in the IF block or the ELSE block you should wrap those in a BEGIN..END construct. |
|
|
|
|
|