Wednesday, 19 September 2018

Script to Find and Update Extra Spaces in String / Column

There come to some scenarios when you need to find out and update Extra Spaces within your Data

Here is the Script to Find Extra Spaces in Column:

SELECT
[Rno]
,[Name] AS StringWithSpace
,LTRIM(RTRIM(REPLACE(REPLACE(REPLACE([Name],CHAR(32),'()'),')(',''),'()',CHAR(32)))) AS StringWithoutSpace
FROM tbl_RemoveExtraSpaces


Here is the Script to Update Extra Spaces in Column:

UPDATE tbl_RemoveExtraSpaces SET Name = LTRIM(RTRIM(REPLACE(REPLACE(REPLACE([Name],CHAR(32),'()'),')(',''),'()',CHAR(32))))

Happy Coding !!!

No comments:

Post a Comment

SQL Audits

1. sys.server_audits What it is: Lists all server-level audit objects . An audit is the top-level object that defines: Where to wri...