Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set multiple variables at once

Status
Not open for further replies.

maccaroo

Programmer
Jan 28, 2005
11
0
0
GB
Hi. Is it possible to set a number of variables in one shot in something like the following manner:

SELECT TOP 1 field1, field2, field3
FROM MyTable
ORDER BY SortOrder ASC

SET @f1 = field1
SET @f2 = field2
SET @f3 = field3

The point is that I don't want to have to run a separate SELECT query for each row in the table.
 
Code:
SELECT TOP 1 @f1=field1, @f2=field2, @f3=field3
FROM MyTable
ORDER BY SortOrder ASC
 
SELECT TOP 1 @f1=field1, @f2=field2, @f3=field3
FROM MyTable
ORDER BY SortOrder ASC


"I'm living so far beyond my income that we may almost be said to be living apart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top