with MyStats as ( select o.name ,o.type_desc ,o.type ,LineCount = len(m.definition) - len(replace(m.definition,char(13),'')) from sys.objects o inner join sys.sql_modules m on o.object_id = m.object_id where 1=1 and o.name not like 'z[_]DeadCode[_]%' and o.name not like 'z[_]OldVersion[_]%' and o.name not like 'aspnet[_]%' and o.name not like '[_]%' and o.name not like 'fn[_]%' and o.name not like 'sp[_]%' and o.name not like 'vw[_]aspnet[_]%' ) select type_desc ,ItemCount = count(2) ,LineCount = sum(LineCount) from MyStats group by type_desc order by type_desc