Though you can assign values to local variables using either SET/SELECT,
There are few differences.
SET can be used for assigning one variable at a time whereas Select can be used for multiple variable Assignments
When using a query to populate a variable, SET will fail with an error, if the query returns more than one value. But SELECT will assign one of the returned rows and mask the fact that the query returned more than one row.
A single SELECT statement assigning values to 3 different variables, is much faster than 3 different SET statements assigning values to 3 different variables. In this scenario, using a SELECT is at least twice as fast, compared to SET.
No comments:
Post a Comment