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

String Full Name 1

Status
Not open for further replies.

MeanJoeGreen13

IS-IT--Management
Jan 6, 2008
15
I have the following that does not seem to work well. It leaves spaces where there is a null value, any idea on what the problem may be?

Set full_name = rtrim(ISNULL(prefx,''))+'' +rtrim(ISNULL(first_name,''))+' ' +rtrim(ISNULL(preferred,''))+' ' +rtrim(ISNULL(middle_name,''))+' ' +
rtrim(ISNULL(last_name,''))+' ' +rtrim(ISNULL(sfx_name,''))
 
Try
Code:
Set full_name = rtrim(ISNULL(prefx,'')+''[COLOR=red])[/color] +rtrim(ISNULL(first_name,'')+' '[COLOR=red])[/color] +rtrim(ISNULL(preferred,''))+' ' +rtrim(ISNULL(middle_name,'')+' '[COLOR=red])[/color] +
rtrim(ISNULL(last_name,'')+' '[COLOR=red])[/color] +rtrim(ISNULL(sfx_name,''))
Noticed the moved left parenthesis.
djj
 
There is no problem. It's doing exactly what you have told it to do.

You will probably need to put the spaces between the names inside case statements so that the space is put in only when there is something directly infront of the space.

(This isn't tested)
Code:
Set full_name = rtrim(ISNULL(prefx,''))+ case when prefx is not null then ' ' else '' end +rtrim(ISNULL(first_name,''))+ case when first_name is not null then ' ' else '' end +rtrim(ISNULL(preferred,''))+ case when preferred is not null then ' ' else '' end  +rtrim(ISNULL(middle_name,''))+ case when middle_name is not null then ' ' else '' end +
rtrim(ISNULL(last_name,''))+ case when last_name is not null then ' ' else '' end +rtrim(ISNULL(sfx_name,''))

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

My Blog
 
I thought about djj's solution when I was typing up mine. I didn't go that route as the rtrim should remove the space that you are adding on (I haven't tested so I'm not 100%).

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

My Blog
 
Denny, Good catch.
You would not want to remove the extra space if there is data. What I usually do is something like:
Code:
CASE WHEN RTRIM(prefx) = '' THEN '' ELSE RTRIM(prefx) + ' ' END
Good luck MeanJoeGreen13

djj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top