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)
 Which value is SELECTed

Author  Topic 

X-Factor
Constraint Violating Yak Guru

392 Posts

Posted - 2003-11-10 : 17:15:55
Hi,

If I have...
SELECT 
@variable = Field1

FROM
table1

ORDER BY
Field1


and table1 has multiple items in it, do I always get the last record in the restult set's value for Field1?

X-Factor

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2003-11-10 : 17:24:15
Order by Field 1 determines the value of @variable.
asc then last record, desc the first.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-11-10 : 17:25:11
Yes you'll always get the last record as long as you provide an ORDER BY statement.

Tara
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-11-11 : 12:29:46
...and it has to a lot more work...

Why not just do

SELECT TOP 1 @variable = Field1
FROM table1
ORDER BY Field1 DESC

But there seems a larger issue here...



Brett

8-)
Go to Top of Page
   

- Advertisement -