Title

Monday, 19 January 2015

TSQL how to remove all characters or text after the last tab space


I have some data that look like this:

Maple Leaf City

This is all in a single column called City.

I want to remove the word City so that the output looks like this:

Maple Leaf

My code below removes the everything after the first space instead of the last.

How do I take this: Maple Leaf City and turn it into Maple Leaf?

This is what I have got:

SELECT LEFT(City, CHARINDEX(' ', City) - 1)  FROM MyTable  WHERE CHARINDEX(' ', City) > 1

My code gives me this: Maple

Answer

No comments:

Post a Comment