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 |
|
harik
Starting Member
3 Posts |
Posted - 2007-03-13 : 05:03:57
|
| I have a table attendence which has got columns empno, date ,timein , timeout. If an employee is absent on a day there will be no row for it. How can i get the days where an employee is absent? |
|
|
mahesh_bote
Constraint Violating Yak Guru
298 Posts |
Posted - 2007-03-13 : 05:24:07
|
| don't u keep absenty records of employee? it would be better the keep such records.Mahesh |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-13 : 07:49:22
|
Do you have a calendar table ?left join to to the attendence table KH |
 |
|
|
harik
Starting Member
3 Posts |
Posted - 2007-03-13 : 10:03:52
|
| No there is no calendar table. But all the days in a month will come in the attendance table date field since all the employees have different off days. I would like to know whether it is possible to get the offday without making another calendar table since all the dates are coming in this table if we are giving the distinct date command. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
michaelxvo
Starting Member
47 Posts |
Posted - 2007-03-14 : 13:30:08
|
| I THINK YOU CAN USE A PROCEDURE LIKE THIS TO CREATE A MONTH. I TEST IT AND IT WORKS UP TO THE POINT " select * from @month"IN YOUR QUERY, YOU WILL REPLACE EMPNO WITH YOUR CORRECT EMPNOdeclare @day varchar(10), @count tinyint, @end tinyint declare @month table(id tinyint identity,dayofmonth smalldatetime)set @count = 1set @end = 31while @count <= @endbegin set @day = '03/'+ rtrim(convert(varchar(2),@count)) + '/2007' insert into @month values(convert(smalldatetime,@day)) set @count = @count + 1 end--select * from @monthselect dayofmonth,a,b,c,dfrom @month left join (select empno a,date b,timein c, timeout dfrom attendance where date between '2007-03-01 00:00:00' and '2007-03-31 23:59:59'and empno = 11) xon convert(char(10),dayofmonth,101) = convert(char(10),b,101) |
 |
|
|
harik
Starting Member
3 Posts |
Posted - 2007-03-18 : 12:14:21
|
| Thanks |
 |
|
|
|
|
|
|
|