Hi,I need to make a simple time logging system for internal use. I want to design the table so that it records an entry when the user logs on in the morning. The user will then make an entry each time they do something different until they logout, so each row in the table will have a single datetime entry.I'm going to use self joins to work out how long each things taken.Here's my 1st draftdrop table #clientscreate table #clients(clientid int identity(1,1),client varchar(10))insert #clientsselect 'Internal' unionselect 'Client 1' unionselect 'Client 2' unionselect 'Client 3' unionselect 'Client 4' drop table #timelogcreate table #timelog(TLid int identity (1,1),Userid int,ClientID int,Taskid int,Start datetime)insert into #timelogselect 1, 5, 3, '2009-16-07 09:00:00.000' unionselect 1, 1, 1, '2009-16-07 09:10:00.000' unionselect 1, 2, 2, '2009-16-07 10:00:00.000' unionselect 1, 5, 5, '2009-16-07 12:00:00.000' unionselect 1, 5, 7, '2009-16-07 13:00:00.000' unionselect 1, 1, 2, '2009-16-07 13:25:00.000' unionselect 1, 3, 7, '2009-16-07 14:00:00.000' unionselect 1, 1, 7, '2009-16-07 15:15:00.000' unionselect 1, 3, 6, '2009-16-07 16:00:00.000' unionselect 1, 2, 2, '2009-16-07 16:30:00.000' unionselect 1, 4, 4, '2009-16-07 17:12:00.000' unionselect 2, 5, 3, '2009-16-07 09:00:00.000' unionselect 2, 5, 2, '2009-16-07 09:34:00.000' unionselect 2, 5, 5, '2009-16-07 12:15:00.000' unionselect 2, 5, 6, '2009-16-07 14:34:00.000' unionselect 2, 5, 4, '2009-16-07 17:56:00.000'drop table #taskcreate table #task(taskId int identity (1,1),Task varchar(100))insert into #taskselect 'Login' unionselect 'Do a calc' unionselect 'Process a leaver' unionselect 'Lunch' unionselect 'Send a letter' unionselect 'Have a meeting' unionselect 'Logout' selecttl1.userid,c.client,t.task,tl1.start startTime,min(tl2.start) StopTime,datediff(mi, tl1.start, min(tl2.start)) DurationMinsfrom #timelog tl1join #timelog tl2on tl2.start > tl1.start join #task ton tl1.taskid = t.taskidjoin #clients c on c.clientid = tl1.clientidwhere tl1.taskid <> 4group by tl1.userid,c.client,t.task,tl1.startorder by tl1.userid, tl1.start
My question is, is performance going to suffer doing self joins to work out the duration of each task when there's a gazillion rows in the table, or would I be better building the app to include start and stop times against each task?Cheers,Yonabout