DCSIMG
SQL,T-SQL - David Birin's blog

Browse by Tags

Different behaviors between select to variable in SQL
I encountered different behaviors between the two syntaxes of select to variable in SQL. The first type of select has the following syntax: SELECT @ Variable = C FROM T and the second syntax: SET @ Variable = ( SELECT C FROM T) When the query result is a single value the behavior of both is the same (as expected the query result will be placed into the variable). Things become more difficult when the query returns more than one result, or zero results as can be seen in the following examples: For...