Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
How can I trim the spaces between lastname and email extension?

Goal: I am updating email Address column that is NULL with First and lastname and email extension.

I was able to trim spaces between firstname and last name for the records that is NULL but cannot get rid of the spaces between last name and email extension.

Email Address column is showing as: John.Doe @xxx.net

need to take the spaces out between LastName and email extension to make it to show: John.Doe@xxx.net

My Code:
UPDATE tbltest
SET [Email Address] = LTRIM((RTRIM(([First Name]))+ '.'+[Last Name]+'@xxx.net'))
WHERE [Email Address] IS NULL




Thank you for your time.
Posted
Comments
Member 12001186 22-Jan-16 13:50pm    
Since you dont want any spaces why not use REPLACE(var, ' ', '') ?

Update the field using the REPLACE function and replace ' ' with ''.

UPDATE tbltest SET [Email Address] = REPLACE([Email Address],' ','');
 
Share this answer
 
Comments
OriginalGriff 22-Jan-16 14:03pm    
Since spaces aren't allowed in email addresses at all, that's the best solution! :thumbsup:
Member 11829482 22-Jan-16 14:50pm    
Thanks solution 2 and yours work.
SQL
--You can also use LTRIM and RTRIM on the LastName like you did with the FirstName or you can use REPLACE function like Michael showed in solution 1.
UPDATE tbltest
SET [EmailAddress] = LTRIM(RTRIM([FirstName]))+ '.' + LTRIM(RTRIM([LastName])) + '@xxx.net'
WHERE [EmailAddress] IS NULL
 
Share this answer
 
Comments
Member 11829482 22-Jan-16 14:50pm    
Thanks solution 1 and your work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900