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

how would I asign values received from a query to variables

Status
Not open for further replies.

belcom125

Programmer
Nov 17, 2004
45
CA
Say if I do a "select top 1 id, name from table" just to get one record, how can I asign the values retrieved from that query to variables @id and @name in a SQL 2000 stored procedure?
 
Declare the variables then use the SET command:

Code:
set @id = (Select....)

[bandito] [blue]DBomrrsm[/blue] [bandito]
 
that is one variable, but I have multiple like "@id, @name, etc" from same query
 
Select @test= field1, @test2 = field2 from table1 where field3 = 'test'

Questions about posting. See faq183-874
 

you should be able to do it using:

select top 1 @id = id, @name = name from employee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top