Click here to Skip to main content
15,900,725 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi
I want to pass the Stored Procedure "1,2,3" as a Integer Array, is this possible in mysql?

Actually I have to do
SQL
select * FROM User WHERE id IN (1,2,3);

I want to pass the Stored Procedure "1,2,3" as a Integer Array

If i use varchar then sometimes the query executes fine But, sometimes it gives no records.


Thanks
Posted
Updated 24-Sep-12 19:43pm
v2

This helps for me to do IN condition
Hope this will help you..

SQL
CREATE  PROCEDURE `test`(IN Array_String VARCHAR(100))
BEGIN
    SELECT * FROM Table_Name
    WHERE FIND_IN_SET(field_name_to_search, Array_String);

END//;


Calling:

SQL
call test('3,2,1');
 
Share this answer
 
 
Share this answer
 
your stored procedure should be like this

SQL
CREATE procedure procedure_name
(
@CLAIM_NOS varchar(max)
)
as
declare @sql_query varchar(max)
set @sql_query='select * from table_name where CLAIMNO in ('+@CLAIM_NOS+')'
exec (@sql_query)


here im retrieving id number from gridview,,,

SQL
string S_selected_Claimno = "";
S_selected_Claimno = S_selected_Claimno + "'" + dataGridView1.Rows[i].Cells[1].Value + "',"


AT last ur parameter string should be like this (front end parameter format)
'1998102600200003','2000041900200001','333333333333333'

this will work ,,try it
NOTE : bt make sure while checking ur SP is working or not pass parameters in the below format (IN the back end)
'''1998102600200003'',''2000041900200001'',''333333333333333'''
 
Share this answer
 
SQL
DELIMITER $$
CREATE PROCEDURE `uh46v_order_status_array_to_table`(IN statuses varchar(255))
    NO SQL
BEGIN
DROP TEMPORARY TABLE IF EXISTS oc_order_status_tmp;

SET @sql = CONCAT('CREATE TEMPORARY TABLE IF NOT EXISTS `oc_order_status_tmp` ( 
					PRIMARY KEY (`order_status_id`)
					)  ENGINE=MyISAM
					AS (SELECT `order_status_id`, `name` FROM `oc_order_status` WHERE `language_id` = 1 AND `order_status_id` in (',
					statuses, '
					))');

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
end$$
DELIMITER ;

Calling
SQL
call uh46v_order_status_array_to_table('1,2,3,4,5');
select * from oc_order_status_tmp;

output
+-----------------+------------+
| order_status_id | name       |
+-----------------+------------+
|               1 | Pending    |
|               2 | Processing |
|               3 | Shipped    |
|               5 | Complete   |
+-----------------+------------+
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900