March 24, 2006 at 9:45 am
Beolw is the tables Structure and dummy data used in Access database
Employee
========
EmpId(Pk int)EName(Text) DeptId(Fk int)
1Rashid1
2Kashif2
3Black1
4White2
5Brown2
Department
==========
DeptId(Pk int)DName(Text)
1Labor
2Secret
3Production
4Purchase
Attendance
==========
AttId(Pk Int)EmpId(Fk int)In/Out_Time(Datetime)Direction
122/5/2006 6:37:02 PM1 // 1 for IN, 0 For OUT
222/5/2006 8:37:02 PM0
322/5/2006 8:50:00 PM1
412/5/2006 8:51:00 PM1
512/5/2006 9:37:02 PM0
622/5/2006 9:40:02 PM0
732/5/2006 6:37:04 PM1
842/5/2006 6:37:06 PM1
952/5/2006 6:37:08 PM1
1052/5/2006 8:40:02 PM0
1142/5/2006 8:40:40 PM0
1232/5/2006 8:40:50 PM0
1323/5/2006 6:37:02 PM1
1423/5/2006 8:37:02 PM0
1523/5/2006 8:50:00 PM1
1613/5/2006 8:51:00 PM1
1713/5/2006 9:37:02 PM0
1823/5/2006 9:40:02 PM0
1933/5/2006 6:37:04 PM1
2043/5/2006 6:37:06 PM1
2153/5/2006 6:37:08 PM1
2253/5/2006 8:40:02 PM0
2343/5/2006 8:40:40 PM0
2433/5/2006 8:40:50 PM0
And 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
format
ENameDName IstDay2ndDay 3rdDay 4thDay5thDay 6thDay 7thDay
Where 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 database
Thnx in Advance
March 27, 2006 at 8:00 am
This was removed by the editor as SPAM
March 30, 2006 at 9:44 am
IMO, you're not likely to get much back against this post. You've put your data and a requirement up, and basically asked the community to do your work for you.
You'll do better at getting reponses, I believe, if you'll go ahead and tackle the problem and then post a specific question when you get stuck.
You may want to consider some of these as you start:
format(mydatefield, "ww") (in case you want actual calendar weeks)
grouping/summing queries
crosstab queries
parameterized queries
As an example of a parameterized query, you can write sql like this:
select mydatefield, field1, field2... from mytable
where mydatefield between [mystartdate] and ([mystartdate] + 6).
If you run that in access with real table and field names, access will prompt you for mystartdate once, and then run.
I'd say put a little more effort into your task and come back when you have a more focussed question.
April 4, 2006 at 9:01 am
Click here to download an Access database that shows you a suggested solution to your question. Review Query4, which is a Crosstab query to show the number of minutes worked by employee by date. But you also need to review Query3 as it shows that there is an error if any employee has multiple In/Out s in one day. There will also be a problem if an employee comes in before midnight, and leaves after midnight. The only way around these two situations would be to write VBA code to pair an employee's In and Out records, and assign the correct date to the minutes worked for that pair of In and Out records.
Hope this helps
[font="Comic Sans MS"]Vic[/font]
www.vicrauch.com
April 4, 2006 at 12:11 pm
A Bundle Of Thnks Rauch! For your nice and Compact solution. Thnx once again
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply