Unix Technical Forum

how to append the % to a IN parameter for stored procedure

This is a discussion on how to append the % to a IN parameter for stored procedure within the MySQL forums, part of the Database Server Software category; --> Hi, i keep getting syntax error I am doing this CREATE PROCEDURE `db_test`.`sp_GetShopsByKeyword`(IN keyword varchar(100)) /*LANGUAGE SQL | [NOT] ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-17-2008, 07:13 AM
Kei Simone
 
Posts: n/a
Default how to append the % to a IN parameter for stored procedure

Hi,

i keep getting syntax error

I am doing this

CREATE PROCEDURE `db_test`.`sp_GetShopsByKeyword`(IN keyword
varchar(100))
/*LANGUAGE SQL
| [NOT] DETERMINISTIC
| { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
| SQL SECURITY { DEFINER | INVOKER }
| COMMENT 'string'*/

BEGIN



SELECT * FROM shops where title like '%' + keyword '%';

END$$


this stored procedure is meant for search purposes.

i am taking in a user input from the text box and then running the
stored procedure where i can return all results whose title contain
the keyword.

How do i achieve that result ? I tried googling a bit but to no avail.

Please advise.

Thank you.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-17-2008, 07:13 AM
Michael Austin
 
Posts: n/a
Default Re: how to append the % to a IN parameter for stored procedure

Kei Simone wrote:
> Hi,
>
> i keep getting syntax error
>
> I am doing this
>
> CREATE PROCEDURE `db_test`.`sp_GetShopsByKeyword`(IN keyword
> varchar(100))
> /*LANGUAGE SQL
> | [NOT] DETERMINISTIC
> | { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
> | SQL SECURITY { DEFINER | INVOKER }
> | COMMENT 'string'*/
>
> BEGIN
>
>
>
> SELECT * FROM shops where title like '%' + keyword '%';
>
> END$$
>
>
> this stored procedure is meant for search purposes.
>
> i am taking in a user input from the text box and then running the
> stored procedure where i can return all results whose title contain
> the keyword.
>
> How do i achieve that result ? I tried googling a bit but to no avail.
>
> Please advise.
>
> Thank you.



try something syntactically correct.

SQL isn't PERL, BASIC or PHP.

try:
like concat('%',keyword,'%');
or if you prefer an ANSI Standard solution:
like '%'||keyword||'%';


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-17-2008, 07:13 AM
Kei Simone
 
Posts: n/a
Default Re: how to append the % to a IN parameter for stored procedure

On Mar 12, 10:47 am, Michael Austin <maus...@firstdbasource.com>
wrote:
> Kei Simone wrote:
> > Hi,

>
> > i keep getting syntax error

>
> > I am doing this

>
> > CREATE PROCEDURE `db_test`.`sp_GetShopsByKeyword`(IN keyword
> > varchar(100))
> > /*LANGUAGE SQL
> > | [NOT] DETERMINISTIC
> > | { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
> > | SQL SECURITY { DEFINER | INVOKER }
> > | COMMENT 'string'*/

>
> > BEGIN

>
> > SELECT * FROM shops where title like '%' + keyword '%';

>
> > END$$

>
> > this stored procedure is meant for search purposes.

>
> > i am taking in a user input from the text box and then running the
> > stored procedure where i can return all results whose title contain
> > the keyword.

>
> > How do i achieve that result ? I tried googling a bit but to no avail.

>
> > Please advise.

>
> > Thank you.

>
> try something syntactically correct.
>
> SQL isn't PERL, BASIC or PHP.
>
> try:
> like concat('%',keyword,'%');
> or if you prefer an ANSI Standard solution:
> like '%'||keyword||'%';


Thank you.

That was fantastic.

Is there any books or online resources you can recommend me?

Is there any advice you can give me?

I am developing a asp.net 2.0 web application running on MySQL 5.0.
there may be some extensive searching functions involved, but my
knowledge of MySQL is limited to writing standard stored procedures
and queries. I know nothing about optimization of search queries or
caching.

Should I upgrade MySQL 5.0 to 6.0?

Thank you.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:04 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com