Control of Flow - where is CASE ?

  • Why isn't CASE supported for flow control in T-SQL ?

    I have to do this ?:

    IF @xyz = 1 THEN

    EXEC dbo.PROC1

    ELSE IF @xyz = 2 THEN

    EXEC dbo.PROC2

    ELSE

    EXEC dbo.PROC3

    END

  • Because T-SQL doesn't like to have flow control.

    Don't forget to remove THEN, this isn't VB. 😛

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Luis Cazares (9/18/2015)


    Because T-SQL doesn't like to have flow control.

    Why exactly ?

    BTW: Thanks for that "THEN" but IMHO that should be optional.

  • Unlike Oracle where CASE can be used for control of flow, T-SQL does not have it overloaded in that manner. Why? I don't know, you'd actually need to go back Sybase Engineers to figure that one out.

  • You can use this type of conditional logic in stored procedures. Dunno if that's stating the obvious or not.


    "If I had been drinking out of that toilet, I might have been killed." -Ace Ventura

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply