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

Remove spaces when concetenating?

Status
Not open for further replies.

mkallover

Programmer
Joined
Feb 6, 2008
Messages
88
Location
US
I'm creating a simple Select query as a source for a Report and in the query I am concatenating several fields like so:

Code:
(PRESBR_LAST_NME & ", " & PRESBR_FRST_NME & " " & PRESBR_MDL_NME & " " & PRESBR_SUFX) AS FullName

The problem is that the data in each field is space filled in order to use all characters. Is there a way to remove the spaces when concatenating so the results don't look like:

Code:
Smith           , John        A        Jr.
 
Use Trim$ on each of your field names.
 
Ahhhh, apparently my Google-Fu was weak this morning when I started looking for a solution. I just found TRIM, RTRIM and LTRIM. So for posterity's sake I replaced my original concatenation with:

Code:
(RTRIM(PRESBR_LAST_NME) & ", " & RTRIM(PRESBR_FRST_NME) & " " & RTRIM(PRESBR_MDL_NME) & " " & RTRIM(PRESBR_SUFX)) AS FullName
[/code}
 
You can also use REPLACE().

Beir bua agus beannacht!
 
Especially when the space is found in the middle of the string :-)

[pipe]
Daniel Vlas
Systems Consultant

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top