Q:

T-SQL get columns of specific type

I am trying to get names of columns with a specific type (so I can dynamically query the result). Code below seems to be getting me close (with i.e. type=56 standing for int) but it just seems to be incorrect. Not to mention that I've failed to find a good mapping from types to int representation.
SELECT c.system_type_id as type
FROM SYS.COLUMNS c
JOIN SYS.TABLES t ON c.object_id = t.object_id   
WHERE t.name = 'MyTableName'

Thanks

A:

You can find the mapping to types in the sys.types catalog view:
SELECT c.name as column_name, ty.name as type_name
FROM SYS.COLUMNS c
JOIN SYS.TABLES t ON c.object_id = t.object_id   
JOIN SYS.TYPES ty ON c.system_type_id = ty.system_type_id
WHERE t.name = 'MyTableName'

