0

I have a SELECT statement that returns 3 values, and I want get the data in those values. Can you help me please?

My code is :

declare @id int
declare @selected_name varchar(50)
declare @selected_age int
declare @selected_salary money

Select 
    name, age, salary 
from 
    people 
where 
    id = @id 

set @selected_name = name 
set @selected_age = age 
set @selected_salary = salary
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
joba
  • 33
  • 1
  • 5

1 Answers1

1

You can do :

select @selected_name = name, @selected_age = age, @selected_salary = salary 
from people 
where id = @id; 

Make sue this will need to have a single/unique entry, if that is not the case then you need top clause :

select top (1) @selected_name = name, @selected_age = age, @selected_salary = salary 
from people 
where id = @id;
Yogesh Sharma
  • 49,870
  • 5
  • 26
  • 52