title: Fixing a mysql function
body: <p>I'm trying to make a mysql function .but it's not working and following is the error:</p>
  
  <blockquote>
    <p>Error code 1064, SQL state 42000: You have an error in your SQL
    syntax; check the manual that corresponds to your MySQL server version
    for the right syntax to use near
    '=(co,co1,co2,co3,co4,co5,co6,co7,co8,co9,co10,co11,co12,co13,co14);'
    at line 58</p>
  </blockquote>
  
  <p>I tried to fix it but no result.</p>
  
  <pre><code>delimiter |
  CREATE FUNCTION KPI15 (s VARCHAR(20000)) RETURNS VARCHAR(20000)
  DETERMINISTIC
  BEGIN
  
             DECLARE str  VARCHAR(2000);
             DECLARE toFind  VARCHAR(2000);
             DECLARE co VARCHAR(2000);
  DECLARE co1 VARCHAR(2000);
  DECLARE co2 VARCHAR(2000);
  DECLARE co3 VARCHAR(2000);
  DECLARE co4 VARCHAR(2000);
  DECLARE co5 VARCHAR(2000);
  DECLARE co6 VARCHAR(2000);
  DECLARE co7 VARCHAR(2000);
  DECLARE co8 VARCHAR(2000);
  DECLARE co9 VARCHAR(2000);
  DECLARE co10 VARCHAR(2000);
  DECLARE co11 VARCHAR(2000);
  DECLARE co12 VARCHAR(2000);
  DECLARE co13 VARCHAR(2000);
  DECLARE co14 VARCHAR(2000);
  DECLARE cpt VARCHAR(21845);
             SET co='';
  SET co1='';
  SET co2='';
  SET co3='';
  SET co4='';
  SET co5='';
  SET co6='';
       SET co7='';
          SET co8='';
            SET co9='';
          SET co10='';
           SET co11='';
         SET co12='';
           SET co13='';
           SET co14='';
             SET cpt='';
             SET str='';
             SET toFind=s;
  
      SET str =SUBSTRING_INDEX(toFind,'sur',1);
          IF (str like ('%CDR%')) =1 THEN set co1 = 'CDR';
        ElSEIF (str like ('%DL DROP TBF%','%TBF FAIL%','%TBF DROP%','%TBF SR%','%DL TBF SR%','%UL FAIL TBF%','%DATA FAIL%','%FAIL TBF%','%DL DROP DATA%'))=1 THEN set co2 = 'FAIL ET DROP TBF';
           ElSEIF (str like ('%SD DROP%','%SDR%'))=1 THEN set co3 ='SDR';
          ElSEIF (str like ('%FAIL TCH%'))=1 THEN set co4 = 'FAIL TCH';
           ElSEIF (str like ('%HO LEVEL EN DL%','%HO QUALITE%','%HO INTERFERENCE%','%INC HO%'))=1 THEN set co5 = 'DEGRADATION HO';
            ElSEIF (str like ('%DEGRADATION DE TOUS LES KPI CS/PS%','%SLEEPING PS%','%SLEEPING CS%','%BAISSE DE TRAFFIC%'))=1 THEN set co6 = 'DEGRADATION DES KPI CS/PS 2G';
         ElSEIF (str like ('%CSSR%'))=1 THEN set co7 = 'CSSR';
          ElSEIF (str like ('%COUPURE BSS%','%CALL DROP BSS%','%DROP BSS%'))=1 THEN set co8 = 'CALL DROP BSS';
        ElSEIF (str like ('%HSPA DROP%','%HSPA RB DROP%','%HSPA Rb DROP%','%HSPA RAB SETUP%','%HSPA RAB SETUP SR%','%SLEEPING HSPA%','%HSPA SSR%','%HSPA SR%'))=1 THEN set co9 = 'HSPA';
             ElSEIF (str like ('%HSUPA RAB SETUP%','%SLEEPING HSUPA%'))=1 THEN set co10 = 'HSUPA';
            ElSEIF (str like ('%R99 DROP%','%R99 RB DROP%'))=1 THEN set co11 = 'R99';
         ElSEIF (str like ('%RRC SETUP SUCCESS OTHER RATE%','%RRC OTHER%','%RRC OTHERS%','%DEGRADATION RRC CS/PS SETUP%','%RRC SETUP SR%','%RRC SETUP SUCC SERV RATE%','%PS RRC SSR%','%PS RRC SETUP SR%'))=1 THEN set co12 = 'RRC';
           ElSEIF (str like ('%CS RAB%','%CS RAB SETUP%','%CS RAB SETUP SR%','%PS RAB DROP%','%PS RAB SETUP SR%'))=1 THEN set co13 = 'RAB';
           ElSEIF (str like ('%PS DROP%','%CS SERVICE DROP%'))=1 THEN set co14 = 'DEGRADATION DES KPI CS/PS 3G';
         ELSE SET co='vid';END IF;
             cpt=(co,co1,co2,co3,co4,co5,co6,co7,co8,co9,co10,co11,co12,co13,co14);
             return cpt;
                END |
             delimiter; 
  </code></pre>