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 |
dupati1
Posting Yak Master
123 Posts |
Posted - 2006-08-04 : 13:42:55
|
Guys,need suggestion on a doing a simple conditional logic in a smarter and efficient way...here is my conditional statement:... If @flag=1 or @flag = 0 Begin 'bunch of related script lines End If @flag=2 or @flag = 0 Begin 'bunch of related script lines End If @flag=3 or @flag = 0 Begin 'bunch of related script lines End... i mean if the @flag is 0 i want to execute all of the lines...if the flag is other than 0 i want to excute only the related script...i know that above logic is simple and kinda brute-force...is there any other "smart" way (may be using a smarter flag or some other conditional looping) of doing this if the number of conditions are more...thanks for any suggestions... |
|
X002548
Not Just a Number
15586 Posts |
|
ramoneguru
Yak Posting Veteran
69 Posts |
Posted - 2006-08-04 : 20:36:05
|
Hmmm, this reminds me of a token ring :-) it seems you will execute every script when @flag = 0 (some startup thing maybe??)Not sure if you can change the logic they set out. I would venture to guess that those 'related scripts' have the ability to change the value of @flag. And if @flag is set to 0 in any 'related script' it might be for some type of recovery or something so the next 'related script' in the IF statements is executed automatically.But if no recovery is necessary then it will just execute whatever script matches the @flag value *shrug*Well, that makes sense in my head at least.--Nick |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2006-08-04 : 20:50:14
|
quote: Originally posted by dupati1 Guys,need suggestion on a doing a simple conditional logic in a smarter and efficient way...here is my conditional statement:... If @flag=1 or @flag = 0 Begin 'bunch of related script lines End If @flag=2 or @flag = 0 Begin 'bunch of related script lines End If @flag=3 or @flag = 0 Begin 'bunch of related script lines End... i mean if the @flag is 0 i want to execute all of the lines...if the flag is other than 0 i want to excute only the related script...i know that above logic is simple and kinda brute-force...is there any other "smart" way (may be using a smarter flag or some other conditional looping) of doing this if the number of conditions are more...thanks for any suggestions...
I don't really see anything "unsmart" or brute force about it. Very straight-forward and logical. If you add other conditions to this that don't make sense or over-complicate it, that's one thing, but as is, it looks fine.- Jeff |
 |
|
dupati1
Posting Yak Master
123 Posts |
Posted - 2006-08-05 : 09:56:08
|
thanks for your suggestions...very much appreciated... |
 |
|
X002548
Not Just a Number
15586 Posts |
Posted - 2006-08-05 : 12:15:08
|
quote: [i]Originally posted by jsmith8858I don't really see anything "unsmart" or brute force about it. Very straight-forward and logical. If you add other conditions to this that don't make sense or over-complicate it, that's one thing, but as is, it looks fine.
Are you a fan of switches?Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2006-08-05 : 12:51:36
|
quote: Are you a fan of switches?Brett
Not sure what you mean... do you mean switch{} as in C++? If so, then sure, why not?- Jeff |
 |
|
|
|
|
|
|