Sebas
Sebas

Reputation: 343

Can't filter rows with % mysql using stored procedure

My idea is to filter rows using % and an IN Variable, I am calling this procedure but it doesn't filter the rows. For example: if user types 09 the all the rows with the 09... should appear. I have also tried to use concat but also can't filter. I would appreciate any help you can give me.

This is the procedure

delimiter //
create procedure p (in cedula1 varchar(10))
begin
    select * from view_pacientes
-- THIS PART IS WRONG BUT I DONT KNOW HOW TO CORRECT IT TO WORK PROPERLY.
    where cedula1+"%" like cedula;

end//

Upvotes: 0

Views: 106

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270483

It think this is the syntax you want in MySQL:

select *
from view_pacientes
where cedula like concat(cedula1, '%') ;

When you are defining a stored procedure in MySQL, I would recommend that you prefix your arguments with something that makes them special. My preference is in_ and out_ for "in" and "out" parameters.

Upvotes: 2

Related Questions