Both work. Which is better? Arguably, there is a slight bit of 'taste', but the recommended way is to use SET. Why?
- It is ANSI compliant, while using SELECT is not.
- It makes code cleaner (this is where 'taste' might come in...)
- SET will assign null if no value is returned, while SELECT won't (so if use a variable in a loop, SELECT will keep the old value).
- SET will throw an error if multiple values are returned, SELECT won't.