Remove Spaces in columns in sql table

Remove Spaces in columns in sql table


        CREATE FUNCTION dbo.TRIM(@string VARCHAR(MAX))
        RETURNS VARCHAR(MAX)
             BEGIN
                  RETURN LTRIM(RTRIM(@string))
             END
       GO




SELECT dbo.TRIM(' aaaaa strig ')
or
UPDATE Table_name SET columnname= dbo.TRIM(columnname))
or
WITH trimmed AS (SELECT LTRIM(RTRIM(fld1)) as fld1, LTRIM(RTRIM(fld2)) as fld2 ....) SELECT...
You can use following query for removing white spaces from all the columns

UPDATE Table_nameSETcolumnname= REPLACE(columnname,' ',''),columnname1= 
  REPLACE(columnname1,' ','')

and so on for as many columns as you have.

Comments

Popular posts from this blog

Google to FTS Syntax Cheat Sheet

What is the use of DBCC commands?

What is difference between DELETE and TRUNCATE commands?