I am attempting to get the last word from table Project in SQL-Server 2017.
My code is as follows:
select
reverse(substring(reverse(ProjectDescription),1, charindex(' ', reverse(ProjectDescription)) -1)) as LastWord
from Project
The code works if I ask isolate the table to a single line, but I need the last word for all lines in the field ProjectDescription.
When I run the code as above, I get the following error:
Invalid length parameter passed to the LEFT or SUBSTRING function.
Please can someone assist me on where I am going wrong.