April 7, 2005 at 6:08 pm
OK old fogey question here:
Why ever use SET for assigning variables (as opposed to the original SELECT)?
i.e. Is there any advantage?
April 8, 2005 at 1:05 am
SET will only allow the expression on the right hand side to assign one value to the variable.
If you use SELECT, the statement might return several rows and only the value from the final one will be assigned to the variable.
For instance, compare the two following statements:
SET @Foo = (SELECT bar FROM dbo.foobar)
SELECT @Foo = bar FROM dbo.foobar
In the first case you would get an error if the SELECT-statement returned several rows, in the second you would not.
April 8, 2005 at 1:51 am
Piggy-backing on Chris, see if this also helps explaining
http://vyaskn.tripod.com/differences_between_set_and_select.htm
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply