SELECT * FROM erp_bbs.usuarios;

# Stored Procedure: LoginGetId

DELIMITER // 
CREATE PROCEDURE SP_LoginGetIds(
    IN username_P VARCHAR(100),
    IN password_P VARCHAR(100),
    OUT userId INT,
    OUT userRoleId INT,
    OUT userEmpresasId INT
)
BEGIN
    IF EXISTS (SELECT * FROM usuarios WHERE user = username_P LIMIT 1)
    THEN
    SELECT id, idRoles, idEmpresas INTO userId, userRoleId, userEmpresasId  FROM usuarios WHERE Upper(user) = UPPER(username_P) AND pwd = MD5(password_P) LIMIT 1;      
    END IF;
END //
DELIMITER ;

CALL SP_LoginGetIds ('sa', 'bbs57', @userId, @userRoleId, @userEmpresasId);
SELECT @userId AS userId;
SELECT @userRoleId AS userRoleId;
SELECT @userEmpresasId AS userEmpresasId;
