Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm getting some of the records good e.g
Last_Name:- COOKIES FASHION BOUT
First_Name:- IQUE
Company:- COOKIES FASHION BOUTIQUE

-----------------------------------
but in other case
Last_Name:- COOL TEXTILE IMPORT
First_Name:- LTD
Company :- COOL TEXTILE IMPORTLTD


But I need the space between
COOL TEXTILE IMPORT LTD there

Need to fix these records..

What I have tried:

SQL
Select *, concat(Ltrim(Rtrim(Last_Name)),Ltrim(Rtrim(First_Name))) as Company from tbl
Go
--
Posted
Updated 18-Dec-18 22:56pm
v2

Select *, Ltrim(Rtrim(Last_Name)) + ' ' + Ltrim(Rtrim(First_Name)) as Company from tbl


However if you're showing this information somewhere else like a form or a website then I'd select the two columns as separate fields and do the concatenation in the display layer.
 
Share this answer
 
You are either looking at changing your data - adding a special characters that you later replace with a space in front of the LTD perhaps - or adding "special cases" where you look for specific endings like LTD, CO, PLC, and so on and specifically leave the spaces there.

Personally, I'd start by looking at where I got the data from, and see if it can be fixed there instead of later when it's used ... it's always messy to fix up data automatically once it's in your DB.
 
Share this answer
 
Comments
Member 13138564 20-Dec-18 10:29am    
But every records doesn't have ltd, co ending.. if we do do so half of the records will be fixed.
There is no solution to your problem because of the way data was stored in first place.
Sometimes you need to add a space, sometimes you don't, there is no way to know when.

The only solution is to not remove spaces when data is stored.
 
Share this answer
 
You just have to know where you want spaces between lastname and first name then those records you have to update in database only
for example : you have to add one more space in First_Name record in db
 
Share this answer
 

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