Author |
Topic |
erwine
Yak Posting Veteran
69 Posts |
Posted - 2007-07-25 : 05:07:55
|
Hi SQL gurus,I have another issue regarding to worker's timesheet:There are 2 tables, timesheet table and publicholiday table. I need to get the first 6 dates within the month where the worker did not come to work on working day.--This table contains timesheet of Employee 111--No record means not workingCREATE TABLE TIMESHEET (EmpID int, Date datetime, TimeIn nvarchar(4), TimeOut nvarchar(4))GOINSERT INTO TIMESHEET SELECT 100, '20070701', 0900, 1800 UNION ALLSELECT 100, '20070702', 0900, 1800 UNION ALLSELECT 100, '20070703', 0900, 1800 UNION ALLSELECT 100, '20070704', 0900, 1800 UNION ALLSELECT 111, '20070701', 0900, 1800 UNION ALLSELECT 111, '20070702', 0900, 1800 UNION ALLSELECT 111, '20070703', 0900, 1800 UNION ALLSELECT 111, '20070704', 0900, 1800 UNION ALLSELECT 111, '20070705', 0900, 1800 UNION ALLSELECT 111, '20070706', 0900, 1800 UNION ALLSELECT 111, '20070707', 0900, 1800 UNION ALLSELECT 111, '20070708', 0900, 1800 UNION ALLSELECT 111, '20070710', 0900, 1800 UNION ALLSELECT 111, '20070711', 0900, 1800 UNION ALLSELECT 111, '20070712', 0900, 1800 UNION ALLSELECT 111, '20070714', 0900, 1800 UNION ALLSELECT 111, '20070715', 0900, 1800 UNION ALLSELECT 111, '20070716', 0900, 1800 UNION ALLSELECT 111, '20070717', 0900, 1800 UNION ALLSELECT 111, '20070718', 0900, 1800 UNION ALLSELECT 111, '20070719', 0900, 1800 UNION ALLSELECT 111, '20070720', 0900, 1800 UNION ALLSELECT 111, '20070721', 0900, 1800 UNION ALLSELECT 111, '20070722', 0900, 1800 UNION ALLSELECT 111, '20070723', 0900, 1800 UNION ALLSELECT 111, '20070724', 0900, 1800 UNION ALLSELECT 111, '20070725', 0900, 1800 UNION ALLSELECT 111, '20070729', 0900, 1800 UNION ALLSELECT 111, '20070730', 0900, 1800 UNION ALLSELECT 111, '20070731', 0900, 1800 GO--This table contains the dates of public holiday during the month.--In my case, sunday is public holiday.CREATE TABLE PUBLICHOLIDAY (Month nvarchar(10), Date datetime)GOINSERT INTO PUBLICHOLIDAY SELECT 'July', '20070701' UNION ALLSELECT 'July', '20070708' UNION ALLSELECT 'July', '20070715' UNION ALLSELECT 'July', '20070722' UNION ALLSELECT 'July', '20070729'GOThe expected result :empid absentdate100 '20070705'100 '20070706'100 '20070707'100 '20070709'100 '20070710'100 '20070711'111 '20070709'111 '20070713'111 '20070726'111 '20070727'111 '20070728'any ideas, anyone?thanks for your attention.cheers,erwine... sql is fun... |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-07-25 : 05:18:27
|
[code]SELECT e.EmpID, d.[DATE], h.[Date]FROM F_TABLE_DATE('2007-07-01', '2007-07-31') d CROSS JOIN EMP e left JOIN PUBLICHOLIDAY h ON d.[DATE] = h.[Date] left JOIN TIMESHEET t ON e.EmpID = t.EmpID AND d.[DATE] = t.[Date]WHERE h.[Date] IS NULLAND t.EmpID IS NULL[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
erwine
Yak Posting Veteran
69 Posts |
Posted - 2007-07-25 : 05:30:09
|
hi, you again khtan. thanks.is F_TABLE_DATE is user-defined function?how do you return a table of one full month? any new feature in 2005? or it's just a loop from startdate to enddate (parameters)?cheers,erwine... sql is fun... |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
erwine
Yak Posting Veteran
69 Posts |
Posted - 2007-07-25 : 09:04:39
|
yeah..i did search for that and found it out.thanks.... sql is fun... |
 |
|
|
|
|