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!

Concatenating blank strings

Status
Not open for further replies.

seekwall

Programmer
Joined
May 14, 2001
Messages
41
Location
GB
I need to be able to derive a single name field from 4 other fields. If I do the following as an example:

declare @title varchar(20)
select @title = 'Mr'
declare @inits varchar(20)
select @inits = 'J'
declare @forename varchar(20)
select @forename = ' '
declare @surname varchar(20)
select @surname = 'Doe'
print @title+' '+@inits+' '+@forename+' '+@surname

I get "Mr J Doe" returned, which is correct.

What I need to do is to be able to return only one space bewteen each populated string no matter where there are blank strings.

Anyone got any ideas ?



 
Use the REPLACE and RTRIM functions.

print Replace(rtrim(@title)+' '+rtrim(@inits)+' '+rtrim(@forename)+' '+rtrim(@surname),' ',' ') Terry

"The greatest obstacle to discovery is not ignorance -- it is the illusion of knowledge." - Daniel J Boorstin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top