4

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

  • possible duplicate of [SQL Server SELECT INTO @variable?](http://stackoverflow.com/questions/4823880/sql-server-select-into-variable) – Will Oct 29 '14 at 22:48

1 Answers1

10
SELECT
    @rlcstallname = stallname,
    @rlcsalesdept = salesdept,
    @rlcpath = [path]
FROM sometable
Felix Pamittan
  • 31,544
  • 7
  • 41
  • 67