Press "Enter" to skip to content

GOTO And Labels In T-SQL

Ryan Desmond demonstrates the purpose of GOTO in T-SQL:

So I was playing around at work today and decided for whatever reason to see how I could get the code I was writing to fire off only in certain situations.

If it’s Sunday maybe, or if this is in a particular environment, or if a record in an admin table was something specific.  I’m not sure how I’ll use this but I stumbled on Labels and decided to play with them.

Ok, so how to get to know labels.  Well, in order to get them to work sometimes I have to create labels that are based on some criteria.

I do try to avoid these as much as possible, but they are valid syntax and I’ve seen a couple of cases where it makes sense to use GOTO.

One Comment

  1. Ryan Desmond
    Ryan Desmond2018-08-28

    Thanks for sharing. I typically stick with IF and CASE but I admit I’ve never found a reason to use this and I don’t know that it will be used in my project but I did find it interesting to discover “a” use for it.

    I would be interested in methods that you’d use instead?

Comments are closed.