USE AdventureWorks SELECT 'Update '+ Table_Name +' SET '+ Column_Name +' = Ltrim(Trim( '+ Column_Name +'))' FROM INFORMATION_SCHEMA.COLUMNS C WHERE TABLE_SCHEMA ='Production' AND Data_Type IN('char','varchar','nchar','nvarchar')
and EXISTS(SELECT Table_Name FROM INFORMATION_SCHEMA.TABLES T WHERE C.Table_Name = T.Table_Name AND Table_Type <>'VIEW')