开发者

How to put multiple batches into a single logical block

I am writing a script that needs to do something like this:

IF [CONDITION]

BEGIN

--EXECUTE LOADS OF BATCHES (I.E. BLOCKS OF CODE WITH 'GO' AT THE END)

END

This appears not to be allowed. The GO statement is not allowed in a BEGIN...END block.

I've also tried this:开发者_高级运维

IF NOT [CONDITION] GOTO GetMeOutOfHere

--EXECUTE LOADS OF BATCHES (I.E. BLOCKS OF CODE WITH 'GO' AT THE END)

GetMeOutOfHere:

But, you guessed it, GOTO doesn't work across batches.

Is there any solution to this confounded conundrum?


Just get rid of the GO statements, they aren't needed as long as you aren't doing structure modifications.

If you are changing the structure, you may need to duplicate your if conditions.


What about this:

IF NOT [CONDITION]

SET NOEXEC ON

--EXECUTE LOADS OF BATCHES (I.E. BLOCKS OF CODE WITH 'GO' AT THE END)

SET NOEXEC OFF

It does seem to work with the script I'm doing right now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜