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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stored proc simple question about select 1

Status
Not open for further replies.

MarkGreen

Technical User
Oct 4, 2002
40
GB
Hi,
I'm new to T-SQL and so this is a simple question, but one that I cannot find the answer to anywhere.

I need to return an integer value from a select statement into a local variable.

I don't understand what happens to the recordset after it has been returned by the select statement. How can you access it?

Thanks,
Mark
 
As long as the SELECT statement returns a single row, you can use this syntax:

Code:
DECLARE @var int

SELECT @var = ColumnName
FROM TableName
WHERE <condition list>
...
--James
 
Thanks, that helped me do what I wanted to do.
Just out of interest, what happens if more than more record is returned?
 
From BOL:

If the SELECT statement returns more than one value, the variable is assigned the last value returned.

Look up assigning variables in BOL for further info. --James
 
If it returns more than one value, you could insert the values of the selct statement into a temp table or table vaiable and then use that to do any furthe r processing you want to do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top