Trim all database fields

后端 未结 9 1946
孤城傲影
孤城傲影 2020-12-29 15:05

Do you know if there\'s a quick way in sql server (via transact-sql) that I could trim all the database string fields.

9条回答
  •  甜味超标
    2020-12-29 15:23

    -- V Quick and Dirty !

    -- If this is to generate code to run on a single table, run this code with text output ;

    set nocount on

    declare @table nvarchar(100) select @table = 'YourTableHere'

    SELECT 'UPDATE ' + @table + ' SET ' SELECT '[' + Column_Name + '] = ' + 'LTRIM(RTRIM([' + Column_Name + '])), ' FROM INFORMATION_SCHEMA.Columns WHERE Table_Name = @table AND Data_Type LIKE '%CHAR%'

    -- Run as text output (Query/Results To... Results To Text -- Copy and paste the text output (excluding the last comma) into a new query window, and run it .

提交回复
热议问题