Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Set VS Select

Author  Topic 

bobmcclellan
Starting Member

46 Posts

Posted - 2011-09-30 : 22:27:13
Is there any benefit to using Set?
using
declare @RangeStart datetime,@RangeEnd datetime
set @RangeStart = '3/1/11'
set @RangeEnd = '3/31/11'

as opposed to
declare @RangeStart datetime, @RangeEnd datetime
select @RangeStart = '3/1/11',@RangeEnd = '3/31/11'

tia,
..bob

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-09-30 : 23:56:06
Should have a look at this article
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2011-10-01 : 05:40:41
"Is there any benefit to using Set?"

We don't bother. Prefer to be able to assign multiple values in one statement.

For @@ERROR and @@ROWCOUNT you have to use SELECT so that both can be assigned in one statement, so to keep in consistent (if nothing else) we use SELECT for all @Variable assignments.

The single-row limit benefit might be a reason, but we would be checking @@ROWCOUNT (and @@ERROR) anyway ...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-01 : 14:00:04
also see

http://weblogs.sqlteam.com/brettk/archive/2007/02/12/60090.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

bobmcclellan
Starting Member

46 Posts

Posted - 2011-10-04 : 11:06:45
Thanks to all of you.
I appreciate the replies and info.
Go to Top of Page
   

- Advertisement -