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?

15th Feb 2020, 4:26 PM
Zlata Zukovich
Zlata Zukovich - avatar
4 odpowiedzi
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
15th Feb 2020, 5:10 PM
Taste
Taste - avatar
0
Then I get an error Incorrect parameters count in the call to native function 'instr'
15th Feb 2020, 6:02 PM
Zlata Zukovich
Zlata Zukovich - avatar
15th Feb 2020, 6:09 PM
Taste
Taste - avatar
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
16th Feb 2020, 4:28 PM
Zlata Zukovich
Zlata Zukovich - avatar