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 

Dennis
Starting Member

11 Posts

Posted - 2007-03-05 : 09:29:14
What is the recommended way to set a variable in a TSQL script? and why?

declare @i int;

set @i = 2;

or

select @i = 2;

is there any difference?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-05 : 09:31:05
the end result is same.

set only allow assignment of single variable but select allow assignment of multiple variable in a single statement


KH

Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-03-05 : 09:31:19
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55620

Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

cykophysh
Starting Member

24 Posts

Posted - 2007-03-06 : 11:35:15
I found an intresting article some years back which I added to my blog for future reference that might help

[url]http://threenineconsulting.com/forum/blogs/cykophysh/archive/2006/12/30/Difference-between-Set-and-Select.aspx[/url]
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-03-06 : 13:08:10
I guess it's kinda bad form to cut and paste another authors text...even though you supplied a link, it could be construed that it was your work...

Or you can not google, and do the leg work on your own...only to have it pointed out to you


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




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

cykophysh
Starting Member

24 Posts

Posted - 2007-03-06 : 13:32:21
Thanks I added another disclaimer in bold just in case
quote:
Originally posted by X002548

I guess it's kinda bad form to cut and paste another authors text...even though you supplied a link, it could be construed that it was your work...

Or you can not google, and do the leg work on your own...only to have it pointed out to you


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




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam







Kind Regards,
Gary

<A href="http://www.threenineconsulting.com" target="_blank" >My Website</a> || <a href="http://threenineconsulting.com/forum/blogs/cykophysh/default.aspx" targer="_blank">My Blog</a>
Go to Top of Page
   

- Advertisement -