What do I do so that in a stored procedure I can save in two variables with INTO in front of a query that returns one or several columns?

2

I explain: It turns out that I have a procedure that establishes two integer parameters, which are then arranged to store each the result of a single value that comes from different columns one for each, the select that I have is something complex, so I'll leave a rather summarized code, where you can understand what you would like to do if you could:

DECLARE idUsuario INT DEFAULT 0;
DECLARE idRepuesto INT DEFAULT 0;

SELECT us.id_usuario INTO idUsuario, us.id_cidudad INTO idCiudad
FROM usuarios as us
WHERE us.id_usuario = 1;

#Comprobando que se guardo bien
SELECT idUsuario; 
SELECT idCiudad;

#Resultado esperado
/* Primer Select 
 _________
|idUsuario|
-----------
|    1    |  
-----------
Segundo Select
 _________
|idCiudad|
-----------
|    10   |  
-----------

*/

I do not know if it can be done in case of not being able to thank me for clarifying why, thank you.

    
asked by Johan Inglorion 17.08.2018 в 21:11
source

1 answer

1

If you can and you would do it this way:

SELECT us.id_usuario, us.id_cidudad
INTO  idUsuario, idCiudad
FROM usuarios as us
WHERE us.id_usuario = 1;
    
answered by 17.08.2018 / 21:22
source