Wednesday, March 21, 2012

Number of lines of code in a SP

Hi,
How to find out the total number of lines in a stored proc programmatically?
Regards
Pradeepselect
sum(len(replace(sc.text, ' ', '_')) - len(replace(replace(sc.text, ' ', '_')
, char(13), ''))) + 1
from sysobjects so
inner join syscomments sc on
so.id = sc.id
where
name = 'myStoredProc'|||I assume this was not a question or am I wrong. And why would you be
interested in the number of lines. If you change the formatting, the
number of lines might change, but the SP is till doing the same ?
Markus|||> And why would you be
> interested in the number of lines.
I can't speak for the OP, but the number procedure lines can be a rough
indicator of application complexity. These kind of metrics can be useful in
estimating development effort for major changes, such as a rewrite or
conversion.
Hope this helps.
Dan Guzman
SQL Server MVP
<m.bohse@.quest-consultants.com> wrote in message
news:1133867063.700631.79970@.g49g2000cwa.googlegroups.com...
>I assume this was not a question or am I wrong. And why would you be
> interested in the number of lines. If you change the formatting, the
> number of lines might change, but the SP is till doing the same ?
> Markus
>|||Thats right Dan. I need it for metrics purpose only.
Regards
Pradeep
"Dan Guzman" wrote:

> I can't speak for the OP, but the number procedure lines can be a rough
> indicator of application complexity. These kind of metrics can be useful
in
> estimating development effort for major changes, such as a rewrite or
> conversion.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> <m.bohse@.quest-consultants.com> wrote in message
> news:1133867063.700631.79970@.g49g2000cwa.googlegroups.com...
>
>|||Could this be easily extended to get the lengths of all stored
procedures in a db?
"daw" <murmax@.rambler.ru> wrote:

>select
> sum(len(replace(sc.text, ' ', '_')) - len(replace(replace(sc.text, ' ', '
_'), char(13), ''))) + 1
>from sysobjects so
> inner join syscomments sc on
> so.id = sc.id
>where
> name = 'myStoredProc'
>|||On Sat, 10 Dec 2005 14:36:24 GMT, John Baima wrote:

>Could this be easily extended to get the lengths of all stored
>procedures in a db?
Hi John,
Length in lines, you mean?
Try
select
name,
sum(len(replace(sc.text, ' ', '_')) - len(replace(replace(sc.text, '
', '_'), char(13), ''))) + 1
from sysobjects so
inner join syscomments sc on
so.id = sc.id
group by
name
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

No comments:

Post a Comment