Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign values to multiple variables from one select statement MS SQL

The code below works. Can this be improved?

declare @rlcstallname varchar(50), @rlcsalesdept varchar(50), @rlcpath varchar(50)

set @rlcstallname   = (select stallname from sometable)
set @rlcsalesdept   = (select salesdept from sometable)
set @rlcpath        = (select [path] from sometable)

I need to know how to get the three values I store into the variables using only one select statement; I find executing 3 select statements excessive.

Thanks

like image 875
Ronan Masangcay Avatar asked Sep 17 '25 00:09

Ronan Masangcay


1 Answers

SELECT
    @rlcstallname = stallname,
    @rlcsalesdept = salesdept,
    @rlcpath = [path]
FROM sometable
like image 155
Felix Pamittan Avatar answered Sep 19 '25 19:09

Felix Pamittan