user5021612
user5021612

Reputation:

How to trim a string from a space

I have a field like

BestStreet 123/56

and I want to get

BestStreet

I've tried:

LEFT(sd.UliceCP, CHARINDEX(' ', sd.UliceCP)-1)

Upvotes: 1

Views: 65

Answers (2)

user7715598
user7715598

Reputation:

Using Substring Also we can get the same

SELECT SUBSTRING(sd.UliceCP,0,CHARINDEX(' ',sd.UliceCP))

Upvotes: 0

John Cappelletti
John Cappelletti

Reputation: 81970

You may want to add a space, just in case one does not exist.

For example: Notice the sd.UliceCP+' '

LEFT(sd.UliceCP, CHARINDEX(' ', sd.UliceCP+' ')-1)

Upvotes: 5

Related Questions