I've created a dynamic SQL script to generate statements to replace empty strings with NULL for every column in every table in my database. I've stored the script to the variable @SQL
.
When I run EXEC @SQL
, it generates the following results:
(No column name) |
---|
UPDATE [TableX] SET [ColumnA] = NULL WHERE [ColumnA] ='' |
UPDATE [TableX] SET [ColumnB] = NULL WHERE [ColumnB] ='' |
UPDATE [TableX] SET [ColumnC] = NULL WHERE [ColumnC] ='' |
UPDATE [TableY] SET [ColumnA] = NULL WHERE [ColumnA] ='' |
UPDATE [TableY] SET [ColumnB] = NULL WHERE [ColumnB] ='' |
UPDATE [TableY] SET [ColumnB] = NULL WHERE [ColumnB] ='' |
And so on... (there is an inconsistent/unknown number of columns and tables, and therefore an inconsistent/unknown number of results).
My problem is that rather than simply returning these statements as results, I want to actually execute all of the individual statements. I would be very grateful if someone could advise me on the easiest way to do so.
Thanks in advance!