mysql - TRIM query on varying character length varchar -
help!
i trying trim below string middle section "ms lync"
"systems & apps -> ms lync -> request change"
i have tried following query still special characters. string lengths change special characters dont:
left(probcodedesc, charindex('-', probcodedesc)) area, substring(probcodedesc, charindex('> ',probcodedesc),charindex('> ', probcodedesc, charindex('>', probcodedesc) - charindex(' ->', probcodedesc))) category, right(probcodedesc, charindex('>', reverse(probcodedesc))) event all & advice appreciated!
i'd use nifty substring_index function doing this.
reference: https://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_substring-index
for example:
set @s = 'systems & apps -> ms lync -> request change'; select trim(substring_index(@s,'->',1)) `area` area ---------------- systems & apps select trim(substring_index(substring_index(@s,'->',-2),'->',1)) `category` category --------- ms lync select trim(substring_index(@s,'->',-1)) `event` event ------------------ request change
Comments
Post a Comment