LIKE %NAME% in a Store Procedure

[expired user #5867]'s profile image [expired user #5867] posted 13 years ago in General Permalink
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's profile image ansgar posted 13 years ago Permalink
I guess it should look like this:
... where street LIKE CONCAT('%', STREET_NAME, '%');
kalvaro's profile image kalvaro posted 13 years ago Permalink
... because, in SQL, strings go single-quoted.
[expired user #5867]'s profile image [expired user #5867] posted 13 years ago Permalink
It worked! Thanks so much!

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