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 |
salmonraju
Yak Posting Veteran
54 Posts |
Posted - 2006-11-01 : 05:20:05
|
i wrote a simple stored procedure create proc mygoto @sub1 varchar(6),@sub2 varchar(6),@sub3 varchar(6) as if(@sub1='fail') goto label if(@sub2='fail') goto label if(@sub3='fail') goto label else goto label2 label:print 'the total result is fail'returnlabel2:print 'the result is pass'here my program is working wellBUT IS THERE ANY PROBLEM IF I USE GOTO WHY I AM ASKING IS IN SOME C-LANGUAGE BOOKS AUTHORS TELLS NOT TO USE GOTO IN MOST OF THE TIME(they prefer function )May i use GOTO IN THIS SITUATION |
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-11-01 : 05:50:03
|
I dont know the specific disadvantage in terms of performance, but i had read some where that using many of GOTO's label it create very difficult to read the code. but why do you want to use GoTo Labels? from the example which you had posted i dont see any use of it..??Chiraghttp://chirikworld.blogspot.com/ |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-11-01 : 10:19:45
|
Dont try to simulate front end code at sqlUse IF ......Begindo what you wantEndELSE IFBegindo what you wantEndELSE IFBegindo what you wantEndMadhivananFailing to plan is Planning to fail |
 |
|
X002548
Not Just a Number
15586 Posts |
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-11-01 : 16:46:12
|
I just wish they allowed this:GOTO @label_name That would make things fun. CODO ERGO SUM |
 |
|
X002548
Not Just a Number
15586 Posts |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-11-06 : 10:29:45
|
for your logic instead of goto's use a bit variable which you set accordingly to success or failure:declare @success bitselect @success = 1if(@sub1='fail')select @success = 0if(@sub2='fail')select @success = 0if(@sub3='fail')select @success = 0if @success = 0print 'the total result is fail'elseprint 'the result is pass'returnGo with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
 |
|
|
|
|