views:

255

answers:

1

I am a little new to store procedures in MySQL and was wondering if I can SELECT multiple columns into multiple variables within the same select query.

for example (iName is the input to the function):

DECLARE iId INT(20);
DECLARE dCreate DATETIME;

SELECT Id INTO iId, dateCreated INTO dCreate FROM products WHERE pName=iName;

Thanks

+2  A: 

Your syntax isn't quite right: you need to list the fields in order before the INTO, and the corresponding target variables after:

SELECT Id, dateCreated INTO iId, dCreate FROM products WHERE pName = iName
martin clayton
Thank you that works fine now.
aHunter