Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2003
    Posts
    35

    Unanswered: exiting a sql batch

    I'd like to be able to code a SQL batch with a return or an exit embedded in it but Sybase does not seem to allow you to do that. For instance, if you run this

    if 1=1
    exit
    go

    select "I don't want to execute this"
    go

    you get a syntax error at the "exit" and you get the output from the select statement. Return does not do what I want either although there's no syntax error. I'm running on ASE 12.0.0.6 and OpenClient 12.0.

    Anyone?

  2. #2
    Join Date
    Mar 2003
    Posts
    10

    Re: exiting a sql batch

    Hi
    Try 'return' instead of 'exit'.
    HTH
    Emmanuel

    Originally posted by RayD
    I'd like to be able to code a SQL batch with a return or an exit embedded in it but Sybase does not seem to allow you to do that. For instance, if you run this

    if 1=1
    exit
    go

    select "I don't want to execute this"
    go

    you get a syntax error at the "exit" and you get the output from the select statement. Return does not do what I want either although there's no syntax error. I'm running on ASE 12.0.0.6 and OpenClient 12.0.

    Anyone?

  3. #3
    Join Date
    Jan 2003
    Posts
    35

    Re: exiting a sql batch

    Originally posted by evinot
    Hi
    Try 'return' instead of 'exit'.
    HTH
    Emmanuel
    Thanks for answering but if you read my post it says that return does not seem to do what I want.

    RD

  4. #4
    Join Date
    Mar 2003
    Posts
    10

    Re: exiting a sql batch

    What is your problem with 'return' ?
    I run a test on my side and it works fine.
    A 'return' should allows you to exit from your batch without problem.
    Emmanuel

  5. #5
    Join Date
    Jan 2003
    Posts
    35

    Re: exiting a sql batch

    Originally posted by evinot
    What is your problem with 'return' ?
    I run a test on my side and it works fine.
    A 'return' should allows you to exit from your batch without problem.
    Emmanuel
    if 1=1
    begin
    return
    end

    select "I don't want to execute this - 1"
    go

    select "I don't want to execute this - 2"
    go


    yields this output ...

    --------------------------------
    I don't want to execute this - 2

    (1 row affected)


    Using return allows you to abort the current batch that's running (delimited by a "go"), but I want it to kick out of the isql session.

  6. #6
    Join Date
    Aug 2002
    Location
    Madrid, Spain
    Posts
    97

    Re: exiting a sql batch

    Originally posted by RayD
    I'd like to be able to code a SQL batch with a return or an exit embedded in it but Sybase does not seem to allow you to do that. For instance, if you run this

    if 1=1
    exit
    go

    select "I don't want to execute this"
    go

    you get a syntax error at the "exit" and you get the output from the select statement. Return does not do what I want either although there's no syntax error. I'm running on ASE 12.0.0.6 and OpenClient 12.0.

    Anyone?
    We use a convoluted trick: set noexec on.
    It's advantage is that settings as this
    are valid across isql batches.

    Note that SQL statements are still being
    parsed for syntax errors and object
    existence, which may give some error
    messages later. Believe me, it's a bit
    scaring when you find a message for
    a statement which is supposed not to
    be executed.

    At the end of our isql file, we used to
    add something like
    print "Everything OK"
    go

    So, "Everything OK" shall be printed
    only if no "set noexec on" was executed;
    that is, if no controled error arose. Hence,
    our way to handle isql execution status is
    to grep "Everything OK" in the log file.

    Regards,
    Mariano Corral

  7. #7
    Join Date
    Mar 2003
    Posts
    10

    Re: exiting a sql batch

    Hi
    As far I can know the command 'quit' from the isql's Prompt allows to exit from the curent isql session .
    So have you tried 'quit' ?
    I used your repro and 'quit' seems to be working fine.
    HTH
    Emmanuel

    Originally posted by RayD
    if 1=1
    begin
    return
    end

    select "I don't want to execute this - 1"
    go

    select "I don't want to execute this - 2"
    go


    yields this output ...

    --------------------------------
    I don't want to execute this - 2

    (1 row affected)


    Using return allows you to abort the current batch that's running (delimited by a "go"), but I want it to kick out of the isql session.

  8. #8
    Join Date
    Jan 2003
    Posts
    35

    Re: exiting a sql batch

    Originally posted by evinot
    Hi
    As far I can know the command 'quit' from the isql's Prompt allows to exit from the curent isql session .
    So have you tried 'quit' ?
    I used your repro and 'quit' seems to be working fine.
    HTH
    Emmanuel
    Thanks for your input but I don't think you understand what I'm asking. You cannot conditionally execute "quit" or "exit". Both of these require being on a line all by themselves (unless you're running a different version that behaves differently, of course). ie.

    1> if 1=2
    2> quit

    C:\>

    This quit isql as soon as I hit enter on line 2. It ignored the if condition and didn't even let me type "go". This is expected, it just does not do what I want. See Mariano's previous post about using set noexec on.

    Thanks to both of you.

  9. #9
    Join Date
    Jan 2003
    Posts
    35

    Re: exiting a sql batch

    found it ...


    if 1=1
    begin
    select syb_quit()
    end

    select "I don't want to execute this - 1"
    go

    select "I don't want to execute this - 2"
    go

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •