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)
 retrieve values into local variables without multiple table scans

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-08-07 : 09:32:05
Cam writes "As I type this I'm convinced that the answer lies just around the bend - but since I'm soon to go around the bend myself, here goes:

I'd like to be able to retrieve the values of a couple of fields in a table into local variables with a single scan. My conceptual syntax would look like:

DECLARE @a int, @b varchar

SET @a, @b = (SELECT a, b FROM table WHERE ID = 1)

--or--
SELECT a,b FROM table WHERE ID = 1 INTO @a, @b

I could create a temp table and fill it with a single scan but that just doesn't seem right (I'd then have to fill the local variables via 2 scans of the temp table) - what am I missing?

Thanks in advance,

Cam"
   

- Advertisement -