Adsense

Friday, June 6, 2014

Query to Get Line Count of a Stored Procedure in SQL Server

The query below will return a programming object along with the number of carriage returns which exist within it.

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