Convert SQL types in destination to SQL type in source
Another little script I needed for today. Feel free to expand on the CASE statement for your own types (which I will do should I need to run this again). /* Will transform destination table's column types to match the source database's (when column names match) codesnippet:83d07e82-3866-4877-849f-0ae06322b9fb */ declare @destination varchar(50) declare @source varchar(50) ---- Configuration ----- set @destination = 'PlanImport' set @source = 'Plan' ------------------------ declare @i int declare @count int declare @sql varchar(8000) declare @columnName varchar(8000) declare @columnType varchar(8000) declare @columns table (id int identity(1,1), columnName varchar(50), columnType varchar(50) ) -- insert source columns that are in destination insert into @columns select source.[Name], (CASE source_types.[Name] WHEN 'decimal' THEN source_types.[Name] + '(' + cast(source.[precision] as varchar(50)) + ',' + cast(source.[scale] as varc...