DEV Community

Query Filter
Query Filter

Posted on

fix select

select
tables.name as table_name,
coalesce(date_counts.date_columns_count, 0) as date_columns_count,
coalesce(image_counts.image_columns_count, 0) as image_columns_count,
coalesce(total_counts.total_columns_count, 0) as total_columns_count
from
(select name, id from sysobjects where type = 'U') as tables
left join
(select c.id, count() as date_columns_count
from syscolumns c
join systypes t on c.usertype = t.usertype
where t.name like 'date%'
group by c.id) as date_counts on tables.id = date_counts.id
left join
(select c.id, count(
) as image_columns_count
from syscolumns c
join systypes t on c.usertype = t.usertype
where t.name like 'image%'
group by c.id) as image_counts on tables.id = image_counts.id
left join
(select c.id, count(*) as total_columns_count
from syscolumns c
group by c.id) as total_counts on tables.id = total_counts.id
order by tables.name

Top comments (0)