Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
majidbhutta
Starting Member
13 Posts |
Posted - 2006-03-24 : 11:36:44
|
Beolw is the tables Structure and dummy data used in Access databaseEmployee========EmpId(Pk int) EName(Text) DeptId(Fk int) 1 Rashid 12 Kashif 23 Black 14 White 25 Brown 2Department==========DeptId(Pk int) DName(Text)1 Labor2 Secret3 Production4 PurchaseAttendance==========AttId(Pk Int) EmpId(Fk int) In/Out_Time(Datetime) Direction1 2 2/5/2006 6:37:02 PM 1 // 1 for IN, 0 For OUT2 2 2/5/2006 8:37:02 PM 03 2 2/5/2006 8:50:00 PM 14 1 2/5/2006 8:51:00 PM 15 1 2/5/2006 9:37:02 PM 06 2 2/5/2006 9:40:02 PM 07 3 2/5/2006 6:37:04 PM 18 4 2/5/2006 6:37:06 PM 19 5 2/5/2006 6:37:08 PM 110 5 2/5/2006 8:40:02 PM 011 4 2/5/2006 8:40:40 PM 012 3 2/5/2006 8:40:50 PM 013 2 3/5/2006 6:37:02 PM 1 14 2 3/5/2006 8:37:02 PM 015 2 3/5/2006 8:50:00 PM 116 1 3/5/2006 8:51:00 PM 117 1 3/5/2006 9:37:02 PM 018 2 3/5/2006 9:40:02 PM 019 3 3/5/2006 6:37:04 PM 120 4 3/5/2006 6:37:06 PM 121 5 3/5/2006 6:37:08 PM 122 5 3/5/2006 8:40:02 PM 023 4 3/5/2006 8:40:40 PM 024 3 3/5/2006 8:40:50 PM 0And so on the attendance data for whole month.What i need is an optimized efficient query that takes a Start_date(DateTime) as an input parameter and returns me the Attendance data of all Employees for one week. Means starting from startdate and ending at startdate+6 days in the following formatEName DName IstDay 2ndDay 3rdDay 4thDay 5thDay 6thDay 7thDayWhere as IstDay to 7thDay Columns contains the value for total Working hrs at that day as IstDay = [{Value of In/Out_Time Column for Max(AttId) When Direction=0}- {Value of In/Out_Time Column for Min(AttId) When Direction=1} Where DatePart(d,In/Out_Time)=DatePart(d,@Start_Time) for any EMpId]2ndDay = [{Value of In/Out_Time Column for Max(AttId) When Direction=0}- {Value of In/Out_Time Column for Min(AttId) When Direction=1} Where DatePart(d,In/Out_Time)=DatePart(d,@Start_Time+1 Day) for any EMpId]3rdDay = [{Value of In/Out_Time Column for Max(AttId) When Direction=0}- {Value of In/Out_Time Column for Min(AttId) When Direction=1} Where DatePart(d,In/Out_Time)=DatePart(d,@Start_Time+2 Days) for any EMpId]4thDay = [{Value of In/Out_Time Column for Max(AttId) When Direction=0}- {Value of In/Out_Time Column for Min(AttId) When Direction=1} Where DatePart(d,In/Out_Time)=DatePart(d,@Start_Time+3 days) for any EMpId]And so on upto 7th day.Now i m in need of an efficient query that returns me the required above result set.NOTE====I am using Access 2000 database so i need a query or anything else that may give me the required output in Access databaseThnx in Advance |
|
|
|
|