drop procedure sp_service_category;
create procedure sp_service_category(a_val int)
BEGIN

Select * from (

SELECT	DISTINCT id, name, description, billing_mod_id, is_system, is_deleted, created_at, 
  REPLACE( REPLACE( SUBSTRING_INDEX(SUBSTRING_INDEX(billing_mod_id, ',', n.digit+1), ',', -1), ']', '') , '[', '') val
FROM
  service_category
  INNER JOIN
  (SELECT 0 digit UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3  UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 ) n
  ON LENGTH(REPLACE(billing_mod_id, ',' , '')) <= LENGTH(billing_mod_id)-n.digit
	) service_category_1
where val = a_val
and is_deleted = '0';
end;
