Skip to main content

Posts

Showing posts from September 25, 2010

What Is The Difference Between Set And Select

Here is The Combined answer that i have collected from various articles and experience. Here is the Difference. 1. SET is the ANSI standard for variable assignment, SELECT is not.   2. You can use SELECT to assign values to more than one variable at a time. SET allows you to assign data to only one variable at a time. Here's how: /* Declaring variables */ DECLARE @Variable1 AS int, @Variable2 AS int /* Initializing two variables at once */ SELECT @Variable1 = 1, @Variable2 = 2 /* The same can be done using SET, but two SET statements are needed */ SET @Variable1 = 1 SET @Variable2 = 2       3. 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) .   4. 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 ...