I am trying to get the number of minutes worked up to / between a specified amount of time and am having a bitch of a time doing it.

here is my query

Code:
SELECT
	dbo.[Names].PersonID,
	dbo.[Names].Person,
	SUM
	(
		
		DATEDIFF
		(
			hh, 
			TD.TimeIn,
			MIN
			(
				ISNULL
				(
					TD.TimeOut, 
					datePart(mm, Getdate()) + '/' + 
					datePart(dd, Getdate()) + '/' + 
					datePart(yyyy, Getdate()) + ' ' + 
					datePart(hh, '8') + ':' + 
					datePart(mi, '00') + ':' + 
					datePart(ss, '00')
				)
			)
		)
		* 60 + 
		DATEDIFF
		(
			mi, 
			TD.TimeIn, 
			MIN
			(
				ISNULL
				(
					TD.TimeOut, 
					datePart(mm, Getdate()) + '/' + 
					datePart(dd, Getdate()) + '/' + 
					datePart(yyyy, Getdate()) + ' ' + 
					datePart(hh, '8') + ':' + 
					datePart(mi, '00') + ':' + 
					datePart(ss, '00')
				)
			)	
		)	
	)	
	AS MinutesWorked

FROM         OrdersData.dbo.newTimeData TD INNER JOIN
                      dbo.[Names] ON OrdersData.dbo.newTimeData.EmployeeID = dbo.[Names].EmployeeID
WHERE     
	(OrdersData.dbo.newTimeData.Description = 'Work') 
AND 
	(DATEPART(yyyy, OrdersData.dbo.newTimeData.TimeIn) = DATEPART(yyyy, GETDATE())) 
AND 
        (DATEPART(dd, OrdersData.dbo.newTimeData.TimeIn) = DATEPART(dd, GETDATE())) 
AND 
	(DATEPART(mm, OrdersData.dbo.newTimeData.TimeIn) = DATEPART(mm, GETDATE()))
AND
	(DatePart(hh, OrdersData.dbo.newTimeData.TimeIn) < '8')

GROUP BY OrdersData.dbo.newTimeData.TimeIn, OrdersData.dbo.newTimeData.TimeOut, dbo.[Names].PersonID, dbo.[Names].Person
basically, I want to take the minutes between when they clocked in and 8am. if they were not in before 8, it will return nothing, if they have not yet clocked out or have clocked out after 8am I want to return the time as 8am, in order to calculate the minutes worked.

After this, I will make the changes so it will specify how many minutes they worked between 8am and 10am, and will adjust accordingly for the hours that I need.

My Min function should return the lowest of the clock out time, or 8am (or 10am for the second query or whatever).

The code is a mess and confusing and not working. There has to be an easier way to do this in SQL Server 2000.