Assuming that a carriage return represents a line of code, this will count the lines of code in a SQL 2008 database:
SELECT
ROUTINE_NAME,
ROUTINE_TYPE,
LEN(ROUTINE_DEFINITION )-len(REPLACE(ROUTINE_DEFINITION,CHAR(10),'')) LOC
FROM INFORMATION_SCHEMA.ROUTINES
COMPUTE SUM(LEN(ROUTINE_DEFINITION )-len(REPLACE(ROUTINE_DEFINITION,CHAR(10),'')))
COMPUTE avg(LEN(ROUTINE_DEFINITION )-len(REPLACE(ROUTINE_DEFINITION,CHAR(10),'')))