Q:

How to set variable from select statement in SQL Server

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

A:

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;

