A rough psuedocode will look like this. However, it has not been tested since I do not have a virtual virtual machine
-- Create a cursor that will iterate through -- all the rows that meet the criteria DECLARE csr CURSOR FOR -- This query attempts to define the set of columns -- that are reals SELECT SC.name AS column_name FROM sys.tables ST INNER JOIN sys.columns SC ON SC.object_id = ST.object_id INNER JOIN sys.types T -- these column names are close but not right ON T.type_id = SC.system_type_id WHERE -- make this your table name ST.name = 'traS' -- look at actual values in sys.types AND T.name = 'real' DECLARE -- this holds the current column name @column_name sysname , @base_query varchar(max) , @actual_query varchar(max) -- template query for fixing what buggered SET @base_query = 'ALTER TABLE traS ALTER COLUMN [<X/>] decimal(18,2) NULL' FETCH NEXT FROM csr INTO @column_name WHILE (@@FETCH_STATUS <> -1) BEGIN IF (@@FETCH_STATUS <> -2) BEGIN BEGIN TRY SET @actual_query = REPLACE(@base_query, '<X/>', @column_name) EXECUTE (@actual_query) END TRY BEGIN CATCH PRINT 'Failed executing statement ' PRINT @actual_query END CATCH END FETCH NEXT FROM csr INTO @colum_name END CLOSE csr DEALLOCATE csr
The orange bar above my head says I'm too slow, but I will send anyway, since I spent too much time typing;)
source share