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)
 simple question

Author  Topic 

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2003-06-05 : 07:08:49
what is the difference between
select @variable = columnName from tablename
and
set @variable=(select columnName from tablename)


Regards,
Harshal.

The Judgement of the Judge is as good as the Judge.

dsdeming

479 Posts

Posted - 2003-06-05 : 08:26:31
About 6 keystrokes. Seriously, although they'll both get you the same data, take a look at the execution plans. They're very different.

Dennis
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-06-05 : 08:50:59
I could be wrong, but i think:

select @var = col from table

will always return the LAST col if there is more than 1 row returned from the select statement.

I would think

set @var = (select ....)

would return the FIRST. could be wrong.

EDIT: just checked it out. The second is NOT valid if more than 1 row is returned from the (SELECT ...) statement. There's your difference.


- Jeff

Edited by - jsmith8858 on 06/05/2003 08:52:52
Go to Top of Page

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2003-06-05 : 09:11:40
quote:

I could be wrong, but i think:

select @var = col from table

will always return the LAST col if there is more than 1 row returned from the select statement.

I would think

set @var = (select ....)

would return the FIRST. could be wrong.

EDIT: just checked it out. The second is NOT valid if more than 1 row is returned from the (SELECT ...) statement. There's your difference.


- Jeff

Edited by - jsmith8858 on 06/05/2003 08:52:52



I agree.
I wanted to know performance wise .
thanks for the reply to both of u.
regards,
Harshal.

The Judgement of the Judge is as good as the Judge.
Go to Top of Page
   

- Advertisement -