0

I would have created the stored procedure, but am failed whenever am trying to call the stored procedure with multiple values into single parameter as stated below.

delimiter //
create procedure sp_country(IN code varchar(50))
begin
SELECT Name, Code2 FROM country where Code2 in (code);
end;//
delimiter ;

when i pass one value as below it will return the one record.

call sp_country ('AF')

but whenever i pass the two more values as below it doesn't return anything.

call sp_country ('AF,AL')

i has been referring some sites but am not get properly in this scenario. can someone please advise me. Thanks.!

Raju
  • 1,183
  • 3
  • 11
  • 19

1 Answers1

0

The problem here is that your select statement will be executed with a where code in 'AF,AL'. Obviously, there aren't any rows with the code as AF,AL.

To get around this problem, you will have to slightly modify your approach of passing parameters to the stored procedure, when you want that parameter to be used in an "In" clause.

Check the following threads for ideas

Passing a varchar full of comma delimited values to a SQL Server IN function

http://www.itdeveloperzone.com/2013/03/using-variable-in-in-clause-in-sql.html

Community
  • 1
  • 1
ArunGeorge
  • 495
  • 5
  • 11