How to find the last word in a string in SQLITE
Posted on 2016-10-29
I have an SQLite database with a Buyers_table which has a column: Buyer.name.
The Buyer.name value has been entered as John Smith, John Q. Smith, John and Betty Smith, etc.
...basically many different "name strings" but with the last_name always the last word, with a preceding " " blank space.
I need to pull out just the lastName, the last word in the string. I can do this successfully ONLY WHEN the Buyer.name field is simply two words such as John Smith.
SELECT substr(Buyer.name, instr(Buyer.name, ' ') + 1) AS last_name
Can anyone help me see how to extract just the last word, the last_name? Yes I can do this in SQL, but this project, database, is SQLite so things like CHARINDEX() cannot be used.
Thanks so much,