0
Select first name from full name
If I had a column (name) that contain fullnames such as "Rassal Peter" or "Mary Smith" but one of string contain only first name like "Sam" When I use this query Substring (name,1,instr(name,' ')) It doesn't return string with one name instead it I get blank string How can I solve it?
4 Respostas
0
maybe by using IF with INSTR since INSTR return non zero value if the substring found
SUBSTRING(name, 1, IF(INSTR(name," ")>0,INSTR(name," "),LENGTH(name)))
it looks messy, but i hope you can write it better than i did
0
Then I get an error
Incorrect parameters count in the call to native function 'instr'
0
its working, look
https://www.db-fiddle.com/f/9TUSKbscReZv9pxTA8oLaS/0
0
¯\_(ツ)_/¯
I have an error
I rewrote a bit
Substring (name,1, if (coalesce(position(' ', in name))=0,(coalesce(position (' ' in (name)),length(name))))) as f_n
But now there is error with syntax