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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting Chars and Trimming 1

Status
Not open for further replies.

abienz

Programmer
Aug 13, 2001
53
0
0
GB
We have a table of names in the format 'John Smith' etc
We need to be able to trim this to the first 6 characters, not including spaces and convert to lowercase if possible.

I've got the 1st 6 characters OK but wondered if there's a way to get rid of the spaces in the middle? e.g.

select left ([fullname],6) for 'John Smith' gives 'John S' when I need 'johnsm'

Any ideas?

Thanks
 
Use the replace function to remove all the spaces and then use the left function to get the first 6 characters.

REPLACE(@var,' ','') -- Replaces all the occurences of a space with ''
 
Ahh of course I was expecting a function like TRIM in VBScript but REPLACE is the obvious answer, thanks, a real case of not beeing able to see the wood for the trees :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top