Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

set VS. select...difference?

Status
Not open for further replies.

karen4201

Programmer
Mar 9, 2006
37
US
what's the difference in SQL Server for these two statements?

set @a = 'hello'

select @a = 'hello'


they seem to have the same result...so what's the difference?
 
Try this and see the difference...

Set @a= myfield from mytable
Select @a= myfield from mytable

-DNG
 
With regard to variables, SET can only be used to assign a value to a single variable. SELECT can be used to assign values to multiple variables. SELECT can pull value(s) from database table(s); SET cannot.

--John [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
Thanks for the info.

Is there any speed or memory issues that would suggest using one approach over the other?
 
SELECTing from database table(s) will take more resources because of data access. Other than that, there is no resource difference in the two statements.

--John [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top