Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2008
    Posts
    186

    Unanswered: A separate RAISERROR question -- Returning immediately

    If I have:
    Code:
    IF @myVar IS NULL RAISERROR('my error', 15, 1)
    I want it to exit the sproc -- that is, I want it to behave like this:
    Code:
    IF @myVar IS NULL
        BEGIN
            RAISERROR('my error', 15, 1)
            RETURN
        END
    Is there a way to accomplish that in a single-line? I have having to include BEGIN...END everywhere just for that!

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by dbguyfh
    Is there a way to accomplish that in a single-line? I have having to include BEGIN...END everywhere just for that!
    Well - you could up the level to a catastrophic error that stops all processing, but I would not recommend that.

    I use snippets in Prompt SQL. There are other tools that do similar. Just use something like that if typing BEGIN...END offends you

  3. #3
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    As it happens, I tend to include BEGIN...END for everything anyway, even for a single line. I prefer the consistency, find it easier to read and it also means I never make the mistake (not that I ever have.... ahem) of adding in a line at a later date that I want executed if the condition is true and then wonder why it executes on every pass.

  4. #4
    Join Date
    Jan 2008
    Posts
    186
    Ahhh okay thanks. I figured so. I will just end up going with BEGIN...END

  5. #5
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    You can add WITH NOWAIT to your RAISERROR statement to ensure it gets processed synchronously.
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

Posting Permissions

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