select t.sp_name, sum(t.lines) - 1 as lines_of_code, type
from
(select o.name as sp_name, o.type,
(len(c.text) - len(replace(c.text, char(10), ''))) as lines
from sysobjects o
inner join syscomments c on c.id = o.id
where o.type not in ('c', 'd')) t
group by t.sp_name, type