Posts
1150
Comments
891
Trackbacks
1
T-SQL: SET vs. SELECT when assigning to variables

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.
posted on Tuesday, August 09, 2005 1:37 PM Print
Comments
No comments posted yet.

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 7 and 4 and type the answer here: