MS SQL 2012 How to break a loop if a variable is empty or null
Posted on 2013-11-15
I currently have some code which does the following:
1. Runs through a temporary table based on an identity field
2. For each identity, stores a value to variable1
3. Stores a value from another table into variable2 based on variable1 being found in a particular column
What I need to do is break out of the loop if it doesn't find a match in the second table based on variable1. I've tried various versions of null, zero and len, but can't get this to work.
I don't want to spend the day butchering the data to put it up here but I think the above should explain what I need. I'm fairly new to SQL, so it's most likely just my lack of understanding it.
I'm awarding 500 points for a quick, working solution.