| Author |
Topic |
|
nirene
Yak Posting Veteran
98 Posts |
Posted - 2008-09-02 : 13:25:00
|
| create table #tmp (Empcd varchar(3) ,AbsentDate datetime)insert into #tmp values ('E1','20080719')insert into #tmp values ('E1','20080720')insert into #tmp values ('E1','20080721')insert into #tmp values ('E1','20080722')insert into #tmp values ('E1','20080723')insert into #tmp values ('E1','20080725')insert into #tmp values ('E1','20080726')insert into #tmp values ('E1','20080727')insert into #tmp values ('E1','20080729')insert into #tmp values ('E1','20080730')insert into #tmp values ('E2','20080708')insert into #tmp values ('E2','20080714')insert into #tmp values ('E2','20080715')insert into #tmp values ('E2','20080718')Declare @FDM DatetimeSet @FDM='2008/09/01'Select Empcd,Convert(Datetime,Min(Absentdate),111) as MiAD,Convert(Datetime,Max(Absentdate),111) as MaAD from #tmp Where AbsentDate>=Dateadd(day,-15,@FDM) and AbsentDate<@FDM Group By EmpcdAnd query which yields Empcd,min & max absentdate.Using this result I want to find out the empcd and the dates of Sundays with Empcd.EgEmpcd DtsE1 24/08/2008E2 10/08/2008E2 17/08/2008Thanks in advanceNirene |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-09-02 : 21:23:48
|
use datename(weekday, daetcol ) to check for 'Sunday' KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
nirene
Yak Posting Veteran
98 Posts |
Posted - 2008-09-02 : 22:09:14
|
| Hai Khtan, Thanks for your reply,I know using datename function we can fetch the sundays.All I want is fetch all dates of sundays for all employees whose min & max absentdate are given in a single SELECT statement.Nirene |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
nirene
Yak Posting Veteran
98 Posts |
Posted - 2008-09-02 : 23:10:03
|
| Totally messed up after seeing MVJ's UDF.Could you do me favour by writing the query for me Khtan.Nirene |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-09-02 : 23:15:01
|
quote: Originally posted by nirene Totally messed up after seeing MVJ's UDF.Could you do me favour by writing the query for me Khtan.Nirene
ha ha  KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-09-02 : 23:21:07
|
I don't know what do you want with your query but this will give the the dates of the SundayDeclare @FDM Datetime, @FDM1 datetimeselect @FDM = '2008/09/01'select @FDM1 = dateadd(day, -15, @FDM)select DATEfrom F_TABLE_DATE(@FDM1, @FDM) dwhere WEEKDAY_NAME = 'Sun' KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
nirene
Yak Posting Veteran
98 Posts |
Posted - 2008-09-03 : 00:49:09
|
| If Result IsEmpcd # MiAD # MaAdE1 # 2008-07-18 00:00:00.000 # 2008-07-30 00:00:00.000E2 # 2008-07-23 00:00:00.000 # 2008-07-31 00:00:00.000Now I want to display all dates of Sundays which falls between MiAD & MaADOutput Shoud beEmpcd # DtsE1 # 24/08/2008E2 # 24/08/2008E2 # 31/08/2008 |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-09-03 : 01:04:43
|
quote: Originally posted by nirene If Result IsEmpcd # MiAD # MaAdE1 # 2008-07-18 00:00:00.000 # 2008-07-30 00:00:00.000E2 # 2008-07-23 00:00:00.000 # 2008-07-31 00:00:00.000Now I want to display all dates of Sundays which falls between MiAD & MaADOutput Shoud beEmpcd # DtsE1 # 24/08/2008E2 # 24/08/2008E2 # 31/08/2008
How can August date falls between the MiAD & MaAD date of July ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
nirene
Yak Posting Veteran
98 Posts |
Posted - 2008-09-03 : 03:12:31
|
| Extremely sorry I have posted the wrong output.It should be for July month.Corrected Output should beE1 # 20/07/2008E1 # 27/07/2008E2 # 27/07/2008 |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-09-03 : 03:33:03
|
[code]SELECT e.Empcd, e.MiAD, e.MaAD, d.[DATE]FROM( SELECT Empcd, CONVERT(datetime,MIN(AbsentDate),111) AS MiAD, CONVERT(datetime,MAX(AbsentDate),111) AS MaAD FROM #tmp GROUP BY Empcd) eINNER JOIN F_TABLE_DATE('20080701', '20080731') d ON d.WEEKDAY_NAME = 'Sun' AND d.DATE >= e.MiAD AND d.DATE <= MaAD[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
nirene
Yak Posting Veteran
98 Posts |
Posted - 2008-09-03 : 04:48:40
|
| Thanks a lot.That solved my problem. |
 |
|
|
|