I have a SQL Server table with 100 columns. I would like to do this to each column:
UPDATE 2011INFODATA
SET [Attribute_Code_1] = ltrim(rtrim(Attribute_Code_1))
WHERE len(ltrim(rtrim(Attribute_Code_1))) > 0
My question is how I can use the informatin_schema.columns to dynamically generate or insert the various column names into the above SQL?
I could of course do it by hand for each column and get the same result. But that would be no fun and I want to use this same sql for many tables.
Something along these lines will do it.
Edit: updated sample SQL to incorporate helpful comments from @billinkc, @Martin Smith, @Aaron Bertrand.