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 2005 Forums
 Transact-SQL (2005)
 TOP with variable assignment

Author  Topic 

simondeutsch
Aged Yak Warrior

547 Posts

Posted - 2010-06-30 : 14:11:24
What's the correct syntax to feed two TOP values into 2 variables?

Like so:

DECLARE @Var1 CHAR(10),@Var2 SMALLMONEY
SELECT @Var1 = TOP 1 Code, @Var2 = PaymentAmount FROM TableName WHERE RowID = 100

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-06-30 : 14:26:51
SELECT TOP 1 @Var1 = Code, @Var2 = PaymentAmount
FROM TableName
WHERE RowID = 100

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-06-30 : 14:27:21
Perhaps you want MAX instead of TOP though. Could you show us a data example?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

simondeutsch
Aged Yak Warrior

547 Posts

Posted - 2010-06-30 : 14:58:07
Thanks!

No, I want TOP, not MAX. Like, return the first row matching x, not necessarily the latest or the greatest.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-06-30 : 15:14:22
How do you define RowID?

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -