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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 better conditional logic

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

Posted - 2006-08-04 : 18:06:53
How is the flag set? I would say that you have to make a decision to set the flag, and I am not a fan of flags


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

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
Go to Top of Page

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
Go to Top of Page

dupati1
Posting Yak Master

123 Posts

Posted - 2006-08-05 : 09:56:08
thanks for your suggestions...very much appreciated...
Go to Top of Page

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?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

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
Go to Top of Page
   

- Advertisement -