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 2000 Forums
 Transact-SQL (2000)
 General T-SQL question

Author  Topic 

nabeel
Starting Member

15 Posts

Posted - 2002-04-12 : 19:55:52
Hi...

What's the difference between using SET to assign a variable a value vs. using SELECT... I've seen both, and I don't get the difference:

SET @variable = 'whatever'

SELECT @variable = 'whatever'

Is one preferred over the other?

Thanks.

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-04-12 : 21:08:48
If you are getting data from a table and want to assign it to a variable, you must use SELECT:

SELECT @numrows=Count(*) FROM pubs..authors

Also, you can only SET one variable in a SET statement, but you can set multiple variables with a SELECT:

SELECT @numrows=Count(*), @avg=AVG(price) FROM myTable

There's no preference really; besides these features, they function in the same way.

Go to Top of Page
   

- Advertisement -