Hugo Kornelis (9/7/2013)
+1
Also: I didn't have any trouble ending up with NULL in @X. As Hugo states, but in other words:
If you set a variable, you have to set it to something. Code with unfilled paths will lead to NULL values.
The thingy about ISNULL() have bitten me before, so I knew what to expect. In fact, I thought that were the caveat to look for in todays question, så I were somewhat miffed when that answer were missing.