vendredi 5 juin 2015

Mysql Syntax "if length then" statement

I have a problem with syntax from mysql. i have my subselect:

(SELECT uniqueid AS uniqueid_idx, calldate, src, dst, dstchannel, billsec, SUBSTR(CONVERT(IF(LENGTH(dst)>8,cdr.dst,CONCAT('67',cdr.dst)),UNSIGNED INTEGER),1,6) prefixo_normal FROM cdr)

Can you see: "if you have cdr.dst > 8 then concat.." now i want verify: "if cdr.dst have <5 then create virtual column name RAMAL"

I have tried this syntax: IF(LENGTH(cdr.dst) <4, THEN cdr.dst AS ramal END

but not working.

How can i do it?

Thank you !

Aucun commentaire:

Enregistrer un commentaire