Note that there are some explanatory texts on larger screens.

plurals
  1. POSET vs. SELECT - What's the difference?
    primarykey
    data
    text
    <p>Can someone please identify the functional/performance differences, if any, between <code>SET</code> and <code>SELECT</code> in T-SQL? Under what conditions should I choose one over the other?</p> <hr> <p><strong>UPDATE:</strong><br> Thanks to all who responded. As a few people pointed out, <a href="http://vyaskn.tripod.com/differences_between_set_and_select.htm" rel="noreferrer">this</a> article by <a href="http://vyaskn.tripod.com/" rel="noreferrer">Narayana Vyas Kondreddi</a> has lots of good info. I also perused the net after reading the article and found <a href="http://ryanfarley.com/blog/archive/2004/03/01/390.aspx" rel="noreferrer">this</a> condensed version by <a href="http://ryanfarley.com/default.aspx" rel="noreferrer">Ryan Farley</a> which offers the highlights and thought I would share them:</p> <ol> <li>SET is the ANSI standard for variable assignment, SELECT is not.</li> <li>SET can only assign one variable at a time, SELECT can make multiple assignments at once.</li> <li>If assigning from a query, SET can only assign a scalar value. If the query returns multiple values/rows then SET will raise an error. SELECT will assign one of the values to the variable and hide the fact that multiple values were returned (so you'd likely never know why something was going wrong elsewhere - have fun troubleshooting that one)</li> <li>When assigning from a query if there is no value returned then SET will assign NULL, where SELECT will not make the assignment at all (so the variable will not be changed from it's previous value)</li> <li>As far as speed differences - there are no direct differences between SET and SELECT. However SELECT's ability to make multiple assignments in one shot does give it a slight speed advantage over SET.</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload