Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi
I have problem in my database.

It is desktop application in VB 6,Database is MSSQL 2014

Our client entered data in address column like below

NO.15, JALAN WELMAN, 
JALAN STORE 
TINGAKT TIGA
RAWANG,


But I need in single line like
NO.15, JALAN WELMAN,JALAN STORE,TINGAKT TIGA,RAWANG,


More then 50000 data in table. Cannot do one by one.

Pls advice me

Maideen

What I have tried:

UPDATE [dbo].[MVendorMaster] SET [ADDRESS]= 	
LTRIM(RTRIM(REPLACE(REPLACE(REPLACE([address],CHAR(32),'()'),')(',''),'()',CHAR(32)))) 
Posted
Updated 26-Apr-17 20:11pm
v2
Comments
PIEBALDconsult 27-Apr-17 0:53am    
Try replacing CHAR(10) and CHAR(13) with COMMAs ',' and then replace ',,' with ',' .

And update your data entry code to fix it before it hits the database.
Maideen Abdul Kader 27-Apr-17 1:28am    
Thank you for reply...
Still same. Is there any other solution?
Pls advice me
Thank you

1 solution

You should try doing the following

SQL
UPDATE MVendorMaster SET ADDRESS = REPLACE(REPLACE(REPLACE([ADDRESS], CHAR(13), ''), CHAR(10), ''), CHAR(9), '')


I believe the CHAR values correspond to the following
CHAR(9) is tab
CHAR(13) is carriage return
CHAR(10) is a line feed
 
Share this answer
 
Comments
PIEBALDconsult 27-Apr-17 9:19am    
But I think he wants to replace newline sequences with COMMAs, as in the example he provided.
David_Wimbley 27-Apr-17 13:12pm    
Well without access to their database or anything like that I can't really help with which REPLACE as you could potentially end up with something like No. 15,,,, (four commas due to one already being in example above) but I would hope that it is pretty clear to just put ',' instead of '' in the UPDATE statement where necessary.

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