# "ListTimeEntriesByCategory" Stored Procedure

Description:

This stored procedure returns a summary of each user's time entries based on a Category.

Definition:

    	CREATE  PROCEDURE TT_ListTimeEntriesByCategory
    	(
    		@CategoryID int
    	)
    	AS

    		SELECT
    			U.UserName,
    			U.UserID,
    			temp.MinEntryDate,
    			temp.MaxEntryDate,
    			Sum(EL.Duration) AS Duration
    		FROM TT_EntryLog EL
    			INNER JOIN TT_Users U
    				ON EL.UserID = U.UserID
    			INNER JOIN (SELECT UserID, MIN(EntryDate) AS MinEntryDate, MAX(EntryDate) AS MaxEntryDate FROM TT_EntryLog GROUP BY UserID) AS temp
    	    		ON temp.UserID = EL.UserID
    		WHERE EL.CategoryID = @CategoryID
    		GROUP BY U.UserName, U.UserID, temp.MinEntryDate, temp.MaxEntryDate

Database Tables Used:

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

The primary key in the Users table is the UserID identity field.