Click here to Skip to main content
15,889,600 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i have a procedure in MSSQL in which i am calling a split function.

why procedure query look like:-

select * from tbl_employee where employeeid in (SELECT Value FROM  dbo.FnSplit(@item_ids,','))


this
dbo.FnSplit
function gives multiple rows in single column.

i need to do same in mysql workbench database. but mysql does not support table datatype. can anyone sugguest me a solution.

What I have tried:

i am trying this using XML but not get success,
Posted
Updated 11-Dec-19 22:05pm

1 solution

You can do a "trick" with group_concat[^], dynamic sql, inserting into a temporary table.

SQL
drop temporary table if exists temp;
create temporary table temp( val char(255) );
set @sql = concat("insert into temp (val) values ('", replace(( select group_concat(@item_ids) as data), ",", "'),('"),"');");
prepare stmt1 from @sql;
execute stmt1;
(Adapted from example at MySQL :: Re: Convert comma separated string to rows[^] )

You would then do
SQL
select * from tbl_employee where employeeid in (select val from temp)
or if you were sure there are no duplicates in the @item_ids list
SQL
select * from tbl_employee inner join temp on val = employeeid
 
Share this answer
 
Comments
TCS54321 12-Dec-19 7:05am    
tnx.

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