First, let me just say that finally, in MS SQL 2008, you can declare and assign variables at the same time!
DECLARE @var1 [type] = [value1], @var2 [type] = [value2], @var3 [type] = [value3]
What's the difference between SET and SELECT? SET sounds better and that's pretty much it. With SET, you can only assign one variable at a time, with SELECT, you can do this:
SELECT @var1 = [value1], @var2 = [value2], @var3 = [value3]
Another great reason to use SELECT for setting variables is this:
SELECT @var1 = [column1], @var2 = [column2], @var3 = [column3
FROM [table]
FROM [table]
20 comments: