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
 SQL Server Development (2000)
 SET or SELECT

Author  Topic 

sica
Posting Yak Master

143 Posts

Posted - 2001-11-29 : 05:03:41
Which is the best way to initiate a variable, with SET or SELECT and why?

I have 10 variables in a sp to do a complicated calculation for every tuple in table and I want to have fresh variables every time I get new values.
Which is the best to use: select or set?

Exemple:

set @var1 = 0
set @var2 = 0
set @var3 = 0
....
set @var10 = 0

OR

SELECT @var1 = 0,@var2 = 0,..,@var10 = 0

Sica

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2001-11-29 : 06:19:54
Hi

Basically there is no difference. The run at the same speed (0ms is pretty negligable ).

According to the ANSI standard (I think....I could be wrong here) you should use SET for single values and SELECT for the results of a query. But I don't think it matters too much.



Damian
Go to Top of Page

LarsG
Constraint Violating Yak Guru

284 Posts

Posted - 2001-11-29 : 08:18:33
set is ansi standard for assigning a value to a variable.


OT:
To assign the value of a query to a variable using ANSI/PSM syntax

set var = (select value from t)

or to assign multiple variables

select value1,value2 into var1,var2 from t

SQL server will have some problem being compliant with the latter though.

Go to Top of Page

sica
Posting Yak Master

143 Posts

Posted - 2001-11-29 : 09:14:31
Thanks a lot guys!
It's exactly what I want to hear.

Sica

Go to Top of Page
   

- Advertisement -