Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MYSQL, set two variables in stored proc with single select statement

So I'd like it to be something like, or have the effect of:

declare vFN varchar(20); 
declare vLN varchar(20);
set vFN, vLN = (select fname, lname from sometable where id = 1);

Obviously, I could do 2 selects, but that seems very inefficient.

tia

like image 588
davej Avatar asked Mar 02 '12 21:03

davej


2 Answers

you should try

declare vFN varchar(20); 
declare vLN varchar(20);
select fname, lname INTO vFN, vLN from sometable where id = 1;

check http://dev.mysql.com/doc/refman/5.0/en/select-into.html for documentation.

like image 66
Jerome WAGNER Avatar answered Oct 16 '22 23:10

Jerome WAGNER


Have two set statements. Set one with the select statement and then copy the value in the first to the second.

declare vFN varchar(20); 
declare vLN varchar(20);
set vFN = (select fname, lname from sometable where id = 1);
set vLN = vFN;
like image 27
DJ Quimby Avatar answered Oct 16 '22 21:10

DJ Quimby