distal-attribute
distal-attribute
distal-attribute
distal-attribute

LIKE %NAME% in a Store Procedure

adamsea888@gmail.com posted 3 years ago in General
Hi,

I have a stored proc wihch takes in one param. It has the following code

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_GetStreetName`(
IN STREET_NAME varchar(50)
)
BEGIN
SELECT `name` as MY_NAME from table_address
where street LIKE %STREET_NAME%;
END//
DELIMITER ;

The above query has a syntax error - complaining about the % signs.

I also used:
where street LIKE STREET_NAME;

and in the parameter, I specified the param value as "%"+street+"%" - but the query returned no results.

My question is, how do I do a [street LIKE '%Brown%'] but from within a stored procedure?

Thanks!
ansgar posted 3 years ago
I guess it should look like this:

... where street LIKE CONCAT('%', STREET_NAME, '%');

kalvaro posted 3 years ago
... because, in SQL, strings go single-quoted.
adamsea888@gmail.com posted 3 years ago
It worked! Thanks so much!

Please login to leave a reply, or register at first.