Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting certain characters from a string

Status
Not open for further replies.

ashab02

Programmer
Jun 28, 2005
87
GB
Hello

I have a set of data which contains address details. What I would like to do is get the first letter of the street name but the problem I have is that some of data contains records like
'Flat 4, Hope Lane'
'Flat 4 Hope Lane'

The code I have is as follows and it only handles the first space

Code:
select ltrim(substring('Flat 4 Hope Lane',charindex(' ', 'Flat 4 Hope Lane'),2))

This returns '4' but I want it to return 'H' as this is the first letter of the street name.

The above code works fine if we have data like '12 Hope Lane'

(I have hardcoded the value for illustration purposes)

Has anyone got any ideas on how I can do this??

Thanks
 
Why don't you just do a replace on the string.

replace(stringfield, ',', '')

Then build your query around that.

Ian
 
i'm not sure how the replcae will help me for the following example

'Flat 4 Hope Lane'
 
It will not do anything.

YOu implied that 'Flat 4 Hope Lane' worked fine.

Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top