Posts Topics Forums Images
Search videos from message boards Videos Search messages from microblogs Microblogs Search messages from imdb.com Imdb Search messages from yuku.com Yuku Search messages from lefora.com (free forums) Lefora
My account: Login | Sign Up
Loading... 

Thread: Re: parsing parameter list to Stored Procedure

Started 1 month, 1 week ago by George Schmidt
Hi Tupa, Try these: select * from user_list where list like concat('%', country, '%');
Site: MySQL AB - MySQL Forums  MySQL AB - MySQL Forums - site profile
Forum: Stored Procedures  Stored Procedures - forum profile
Total authors: 4 authors
Total thread posts: 5 posts
Thread activity: no new posts during last week
Domain info for: mysql.com

Other posts in this thread:

Devart Team replied 1 month, 1 week ago
To support lists, you could use a temporary table instead of a procedure parameter: CREATE TEMPORARY TABLE list_table( country VARCHAR(255) ); INSERT INTO test.ttt VALUES ('MY'),('ID'),('TW'); Then, just rewrite your SELECT: select * from user_list where country IN (SELECT country FROM list_table); Devart Company, Database development tools http://www.devart.com...

Peter Brawley replied 1 month, 1 week ago
Tupa, A simple way to do that is with PREPARE: [code] DROP PROCEDURE IF EXISTS spMySampleStoredProc; DELIMITER go CREATE PROCEDURE spMySampleStoredProc( list varchar(1000) ) BEGIN SET @sql=concat( 'select * from user_list where country in(', list, ')' ); PREPARE stmt FROM @sql; EXECUTE @sql; DROP PREPARE stmt; END; go DELIMITER ; PB http://www....

Tupa Panjaitan replied 1 month, 1 week ago
thanks Peter, it works.. but there is a correction: not EXECUTE @sql; but EXECUTE stmt; but Overall good. thanks.

Peter Brawley replied 1 month, 1 week ago
Yep, thx, corrected.

 

Top contributing authors

Name
Posts
Peter Brawley
3
user's latest post:
Re: parsing parameter list to...
Published (2009-11-10 10:49:00)
Yep, thx, corrected.
Tupa Panjaitan
1
user's latest post:
Re: parsing parameter list to...
Published (2009-11-09 21:22:00)
thanks Peter, it works.. but there is a correction: not EXECUTE @sql; but EXECUTE stmt; but Overall good. thanks.
Devart Team
1
user's latest post:
Re: parsing parameter list to...
Published (2009-11-09 05:57:00)
To support lists, you could use a temporary table instead of a procedure parameter: CREATE TEMPORARY TABLE list_table( country VARCHAR(255) ); INSERT INTO test.ttt VALUES ('MY'),('ID'),('TW'); Then, just rewrite your SELECT: select * from user_list where country IN (SELECT country FROM list_table); Devart Company, Database development tools http://www.devart.com/dbforge .
George Schmidt
1
user's latest post:
Re: parsing parameter list to...
Published (2009-11-09 05:03:00)
Hi Tupa, Try these: select * from user_list where list like concat('%', country, '%');

Related threads on "MySQL AB - MySQL Forums":

Related threads on other sites:

Thread profile page for "Re: parsing parameter list to Stored Procedure" on http://www.mysql.com. This report page is a snippet summary view from a single thread "Re: parsing parameter list to Stored Procedure", located on the Message Board at http://www.mysql.com. This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity