Invalid length parameter passed to the LEFT or SUBSTRING function ERROR msg

Viewed 1280

I am working on a query for work. I am attempting to pull the SECOND WORD of a stop name, separated by spaces.

So if the stop name is "Jane Doe" I want to pull "Doe."

I have a field that I am trying to define in sql, and it looks like this:

[pull the second word] = SUBSTRING([STOP_NAME], (CHARINDEX(' ', [STOP_NAME], 1)) + 1, (CHARINDEX(' ', [STOP_NAME], CHARINDEX(' ', [STOP_NAME], 1) + 1)) - (CHARINDEX(' ', [STOP_NAME], 1)) - 1) 

When I type this in, I get the following error message:

Invalid length parameter passed to the LEFT or SUBSTRING function.

What am I doing wrong?

UPDATED:

I am trying to pull the second word only. If the stop name had been "Caroline Jane Doe", then I want to pull just "Jane."

THanks!

2 Answers
Related