March 18, 2008 at 7:10 pm
I am trying to understand how to use RTRIM and LTRIM.
Example: FirstName LastName - how do you remove the space between FirstName and LastName to make it FirstNameLastName.
Thank you in advance for your assistance.
March 18, 2008 at 7:12 pm
If 'FirstName LastName' is in a single column, then...
SELECT REPLACE(namecolumn,' ','')
--Jeff Moden
Change is inevitable... Change for the better is not.
March 18, 2008 at 7:32 pm
Thanks!!! 🙂
March 18, 2008 at 7:36 pm
If in multiple columns and you've got leading or trailing spaces:
CREATE TABLE #NAMES
(FirstName varchar (25),
LastName varchar (25))
INSERT INTO #NAMES
SELECT 'Bob ','Johnson ' UNION
SELECT ' Bob',' Johnson' UNION
SELECT ' Bob ',' J. Johnson '
SELECT FirstName, LastName FROM #NAMES
SELECT RTRIM (LTRIM(Firstname)) , RTRIM(LTRIM (LastName)) FROM #NAMES
SELECT RTRIM (LTRIM(Firstname)) + RTRIM(LTRIM (LastName)) FROM #NAMES
SELECT RTRIM (LTRIM(Firstname + LastName)) FROM #NAMES
DROP TABLE #NAMES
Todd Carrier
MCITP - Database Administrator (SQL 2008)
MCSE: Data Platform (SQL 2012)
March 18, 2008 at 8:36 pm
s43s (3/18/2008)
Thanks!!! 🙂
You bet... thank you for the feedback. If you want to learn more, take a look at Todd's code. It's a good example of what the trim functions can actually do.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply