SELECT
(case when a.colorder=1 then d.name else '' end) N'TabName',
(case when a.colorder=1 then d.id else '' end) N'TabId',
a.colorder N'keyno',
a.name N'colname',
b.name N'DbType',
a.length N'Size',
(case a.status when 72 then 'Output' else 'Input' end) N'Dir'
FROM syscolumns a left join systypes b on a.xusertype=b.xusertype
inner join sysobjects d on a.id=d.id and d.xtype='P' and d.Status>0
order by object_name(a.id),a.colorder