# "ListCategoriesByProject" Stored Procedure

Description:

This stored procedure lists Category summary information based on the Project ID parameter passed in.

Definition:

    	CREATE    PROCEDURE TT_ListCategoriesByProject
    	(
    		@ProjectID int
    	)
    	AS

    	SELECT C.CategoryID,
    		C.Name,
    			C.Abbreviation AS CategoryShortName,
    			C.EstDuration,
    			ISNULL(Sum(EL.Duration), 0) AS ActualHours
    	FROM TT_Categories C
    		LEFT OUTER JOIN TT_EntryLog EL
    			ON C.CategoryID = EL.CategoryID
    	WHERE C.ProjectID = @ProjectID
    	GROUP BY C.CategoryID, C.Name, C.Abbreviation, C.EstDuration

Database Tables Used:

The primary key in the Categories table is the CategoryID identity field. There is a foreign key relationship between the field CategoryID and the Category table's primary key, which will force referential integrity upon inserts and updates.

The primary key in the EntryLog table is the EntryLogID identity field.