Horrible line calculations

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

SELECT TOP 100
  Id as [Post Link],
  OwnerUserId as [User Link],
  LEN(Body) as Length,
  LEN(Body) - LEN(REPLACE(Body,CHAR(10),'')) as Lines,
  (LEN(Body) - LEN(REPLACE(Body,CHAR(10)+'    ',''))) / 5
  + (LEN(Body) - LEN(REPLACE(Body,CHAR(10)+CHAR(9),''))) / 2 as CodeLines
FROM
  Posts
WHERE
  PostTypeId = 2
ORDER BY
  CodeLines DESC

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results