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

Removing ALL Spaces from Variables

Status
Not open for further replies.

quinnipiac0807

Programmer
Oct 25, 2004
38
US
This could be a dumb question but I'll give it a go anyway. I'm using SQL Server 2000, and I'm trying to take a variable and make sure it has no spaces in it, ANYWHERE!!! As easy at this seems it's really confusing me.

Ex. - If a varibalbe looks like this 'Lee Ann', I want to change it to this, 'LeeAnn'.

The reason I'm doing this is because I'm creating email addresses from a very long list of first names and last names, and spaces are a no go in email addresses.

I know this is probably pretty easy, but thanks in advance for the help.
 
use the Replace function

Replace('Lee Ann', ' ', '')

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Code:
declare @text varchar (10) ,@textnospace varchar (10)
set @text = 'Dave Hull'
set @textnospace = replace(@text,' ','')
select @text
select @textnospace

[bandito] [blue]DBomrrsm[/blue] [bandito]

[blue]Software code, like laws and sausages, should never be examined in production[/blue][black] - [/black][purple]Edward Tenner[/purple]
 
Thanks. I was trying to use the trim function which was, obviously, only taking care of half of my problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top