Skip to content

Instantly share code, notes, and snippets.

@matt40k
Created December 5, 2016 15:15
Show Gist options
  • Save matt40k/a49991e64b106a23889c4c6647eb0738 to your computer and use it in GitHub Desktop.
Save matt40k/a49991e64b106a23889c4c6647eb0738 to your computer and use it in GitHub Desktop.
Oh, change the old source format will you. Well fine, I'll throw a view over the top with some basic casting
select
'[' + c.name + '] = cast('+c.name+' as ' + ty.name + case when ty.name = 'varchar' then '(' + cast(c.[max_length] as varchar(4)) + '))' else ')' end
from
sys.[all_columns] c inner join sys.tables t on c.[object_id] = t.[object_id] inner join sys.types ty on c.[system_type_id] = ty.[system_type_id] where t.name = 'TABLE' and schema_name(t.schema_id) = 'SCHEMA'
order by
c.[column_id] asc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment