Author |
Topic |
immad
Posting Yak Master
230 Posts |
Posted - 2013-06-25 : 03:05:35
|
i want to take a sum of time just like thistime09:38:0010:41:0008:55:0009:43:0007:36:0007:03:0009:45:00---------63:21:00 Result---------time datatype is datetimeThanks for the helpimmad uddin ahmed |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-25 : 03:14:45
|
[code]SELECT CAST(((DATEDIFF(dd,0,AggTimedate) * 24) + DATEPART(hh,AggTimedate)) AS varchar(5)) + ':' + DATENAME(mi,AggTimedate) AS ResultFROM(SELECT DATEADD(mi,SUM(DATEDIFF(mi,0,time)),0) AS AggTimedateFROM table)t[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
immad
Posting Yak Master
230 Posts |
Posted - 2013-06-25 : 04:25:32
|
SELECT CAST(((DATEDIFF(dd,0,AggTimedate) * 24) + DATEPART(hh,AggTimedate)) AS varchar(5)) + ':' + DATENAME(mi,AggTimedate) AS ResultFROM (SELECT DATEADD(mi,SUM(DATEDIFF(mi,0,spendtime)),0) AS AggTimedateFROM attend_log where eid=17090 and date >'20130101' and date <'20130131')ti want to show eid column tooeid-----------result17090--------163:54immad uddin ahmed |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2013-06-25 : 04:27:09
|
[code]SELECT eid,CAST(((DATEDIFF(dd,0,AggTimedate) * 24) + DATEPART(hh,AggTimedate)) AS varchar(5)) + ':' + DATENAME(mi,AggTimedate) AS ResultFROM(SELECT eid,DATEADD(mi,SUM(DATEDIFF(mi,0,spendtime)),0) AS AggTimedateFROM attend_log where eid=17090 and date >'20130101' and date <'20130131'group by eid)t[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-25 : 04:30:20
|
quote: Originally posted by immad SELECT CAST(((DATEDIFF(dd,0,AggTimedate) * 24) + DATEPART(hh,AggTimedate)) AS varchar(5)) + ':' + DATENAME(mi,AggTimedate) AS ResultFROM (SELECT DATEADD(mi,SUM(DATEDIFF(mi,0,spendtime)),0) AS AggTimedateFROM attend_log where eid=17090 and date >'20130101' and date <'20130131')ti want to show eid column tooeid-----------result17090--------163:54immad uddin ahmed
With 100 + posts do you mean you still dont know how to add an additional column also to the existing resultset?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
immad
Posting Yak Master
230 Posts |
Posted - 2013-06-25 : 04:47:43
|
quote: Originally posted by visakh16
quote: Originally posted by immad SELECT CAST(((DATEDIFF(dd,0,AggTimedate) * 24) + DATEPART(hh,AggTimedate)) AS varchar(5)) + ':' + DATENAME(mi,AggTimedate) AS ResultFROM (SELECT DATEADD(mi,SUM(DATEDIFF(mi,0,spendtime)),0) AS AggTimedateFROM attend_log where eid=17090 and date >'20130101' and date <'20130131')ti want to show eid column tooeid-----------result17090--------163:54immad uddin ahmed
With 100 + posts do you mean you still dont know how to add an additional column also to the existing resultset?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs
i am doing thisSELECT CAST(((DATEDIFF(dd,0,AggTimedate) * 24) + DATEPART(hh,AggTimedate)) AS varchar(5)) + ':' + DATENAME(mi,AggTimedate) AS SpendtimeFROM(SELECT g.eid,e.ename,DATEADD(mi,SUM(DATEDIFF(mi,0,spendtime)),0) AS AggTimedateFROM attend_log g left join employee e on g.eid=e.eidwhere g.eid=17090 and date >'20130101' and date <'20130131'group by g.eid,e.ename)timmad uddin ahmed |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-25 : 04:50:08
|
without putting the required column in the final select how do you think you'll get it displayed in the resultset?SELECT eid,ename, CAST(((DATEDIFF(dd,0,AggTimedate) * 24) + DATEPART(hh,AggTimedate)) AS varchar(5)) + ':' + DATENAME(mi,AggTimedate) AS SpendtimeFROM(SELECT g.eid,e.ename,DATEADD(mi,SUM(DATEDIFF(mi,0,spendtime)),0) AS AggTimedateFROM attend_log g left join employee e on g.eid=e.eidwhere g.eid=17090 and date >'20130101' and date <'20130131'group by g.eid,e.ename)t ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
immad
Posting Yak Master
230 Posts |
Posted - 2013-06-25 : 06:22:22
|
SELECT EID,NAME,Late,Halfday,Absent,OFFDAY,CAST(((DATEDIFF(dd,0,AggTimedate) * 24) + DATEPART(hh,AggTimedate)) AS varchar(5)) + ':' + DATENAME(mi,AggTimedate) AS SPENDTIMEFROM(SELECT g.EID,e.ename [NAME],sum(case when g.Remarks = 'Late' then 1 else 0 end) as LATE,sum(case when g.Remarks = 'HALF DAY' then 1 else 0 end) as HALFDAY,sum(case when g.Remarks = 'ABSENT' AND G.TIMEIN IS NULL AND G.TIMEOUT IS NULL then 1 else 0 end) as Absent,sum(case when g.Remarks = 'OFF DAY' then 1 else 0 end) as OFFDAY,DATEADD(mi,SUM(DATEDIFF(mi,0,spendtime)),0) AS AggTimedateFROM attend_log g left join employee e on g.eid = e.eidwhere g.eid=17090 and date >'20130101' and date <'20130131' group by g.eid,e.ename)tITS GIVE ME THIS RESULTEID--------NAME--------LATE-HALFDAY---ABSENT---OFFDAY--SPENDTIME17090------ABCD----------6-----2------------0----------0----------163:54ACTUAL RESULT IS THISEID---------NAME--------LATE-HALFDAY-ABSENT---OFFDAY--SPENDTIME17090------ABCD----------6------2-----------6----------4---------163:54immad uddin ahmed |
 |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-06-25 : 06:32:11
|
Cross check once whether those case conditions satisfied or not in the specified duration (date>= '20130101' and date <='20130131' ) -- May be date condition is inclusive--Chandu |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-25 : 06:36:10
|
how do you expect us to find the issue when we dont have any idea of what your rules are for determining ABSENT? As of now you're trying to take it from attend_log which i'm not sure will have details for absent days.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2013-06-25 : 06:48:18
|
post some sample data from attend_log for 17090, inclusive of the ABSENT & OFFDAY records KH[spoiler]Time is always against us[/spoiler] |
 |
|
immad
Posting Yak Master
230 Posts |
Posted - 2013-06-25 : 06:52:59
|
BUT ITS NOT UPDATE ABSENT AND OFFDAY ONLY UPDATE LATES AND HALFDAYBECOUSE ABSENT AND OFF DAY ROWS NOT INSERT IN ATTEND_LOG TABLEALTER procedure [dbo].[AT](@empid nvarchar(50),@department nvarchar(50),@from datetime,@to datetime)asbeginselect[date],min([Timein]) as First_Record,sum(DATEDIFF(minute, [Timein], [Timeout])) as Time_Minutesinto #temp1 from attend_logwhere eid = @empidgroup by [date]selectE.CID,E.BID,t2.[date],t.ebid,t2.Eid,e.ename Employeename,case when datediff(dd,0,t2.date)%7 < 6 then t4.shift else 'O' end as shift,d.name Designation,t5.Dname Department,t.timein as timein,t.[Timeout] as Timeout,CASE WHEN Seq=1 THEN CONVERT(VARCHAR(8), DATEADD(minute, Time_Minutes, 0), 108) ELSE NULL END AS SpendTime,CONVERT(VARCHAR(8), DATEADD(minute, ABS(t4.minute - Time_Minutes), 0), 108) as excesshorttime,case when (t4.minute - Time_Minutes) > 0 then 'Short'when (t4.minute - Time_Minutes) < 0 then 'Excess'else NULL end as ExcessShort,case when t.[timein] is null and t.[timeout] is null and datediff(dd,0,t2.date)%7 < 6 then 'ABSENT' when t.[timein] is null and t.[timeout] is null then 'OFF DAY'WHEN CONVERT(VARCHAR(10), t.[Timein], 108) >= CONVERT(VARCHAR(10), t4.ltime, 108) AND spendtime IS NOT NULL AND ( t4.minute - Time_Minutes) >= 120 THEN 'LATE & HALF DAY'WHEN CONVERT(VARCHAR(10), t.[Timein], 108) >= CONVERT(VARCHAR(10), t4.ltime, 108) AND spendtime IS NOT NULL THEN 'LATE'WHEN ( t4.minute - Time_Minutes) >= 120 and spendtime is not null THEN 'HALF DAY'ELSE '' END AS Remarks,case when t.BID = 2 and t.EBID = 1 then 'ITL 2'when t.BID = 1 and t.EBID = 2 then 'ITL 1'else ''endComments FROM (SELECT eid,[date] FROM (select distinct eid from attend_log)a cross join dbo.calendartable(@from,@to,0,0)b) t2 left join (select row_number() over (partition by [date],eid ORDER BY timein ASC) AS Seq ,sum(DATEDIFF(minute, [Timein], [Timeout])) OVER (PARTITION BY [date],eid) AS Time_Minutes ,* FROM attend_log) ton t.[date] = t2.[date] and t.eid = t2.eidleft join employee e on e.eid = t.eidleft join designation d on e.designationid = d.designationidLEFT OUTER JOIN FRoaster (@empid) T3 ON e.EID = T3.EID AND DATEPART(YYYY,T.DATE) = T3.Year AND DATEPART(MM,T.DATE) = T3.Month AND DATEPART(DD,T.DATE) = T3.DayLEFT OUTER JOIN ShiftView T4 ON T3.SName = T4.ShiftLEFT OUTER JOIN Department T5 ON T5.did = e.didwhere t5.did = @department or t2.eid=@empidorder by t2.[date], t.[Timein]update ATTEND_LOG setexcessshort = case when (t4.minute - Time_Minutes) > 0 Then ' ' else ' ' end+ CONVERT(VARCHAR(8), DATEADD(minute, ABS(t4.minute - Time_Minutes), 0), 108) ,SpendTime = CONVERT(VARCHAR(8), DATEADD(minute, Time_Minutes, 0), 108) ,remarks = case when t.[timein] is null and t.[timeout] is null and datediff(dd,0,t2.date)%7 < 6 then 'ABSENT' when t.[timein] is null and t.[timeout] is null then 'OFF DAY'WHEN CONVERT(VARCHAR(10), t.[Timein], 108) >= CONVERT(VARCHAR(10), t4.ltime, 108) AND spendtime IS NOT NULL AND ( t4.minute - Time_Minutes) >= 120 THEN 'LATE & HALF DAY'WHEN CONVERT(VARCHAR(10), t.[Timein], 108) >= CONVERT(VARCHAR(10), t4.ltime, 108) AND spendtime IS NOT NULL THEN 'LATE'WHEN ( t4.minute - Time_Minutes) >= 120 and spendtime is not null THEN 'HALF DAY'ELSE '' END from ATTEND_LOG tleft join #temp1 t2 on t.[date]=t2.[date] and t.[Timein] = t2.First_Recordleft join employee e on e.eid = t.eidleft join designation d on e.designationid = d.designationidLEFT OUTER JOIN FRoaster (@EmpID) T3 ON e.EID = T3.EID AND DATEPART(YYYY,T.DATE) = T3.Year AND DATEPART(MM,T.DATE) = T3.Month AND DATEPART(DD,T.DATE) = T3.DayLEFT OUTER JOIN ShiftView T4 ON T3.SName = T4.ShiftLEFT OUTER JOIN Department T5 ON T5.did = e.didwhere t.eid=@empidendimmad uddin ahmed |
 |
|
immad
Posting Yak Master
230 Posts |
Posted - 2013-06-25 : 07:12:17
|
SELECTEID,LATE,[HALF DAY],ABSENT,[OFF DAY],[EXCESS / SHORT],ExcessShort,CAST(((DATEDIFF(dd,0,AggTimedate) * 24) + DATEPART(hh,AggTimedate)) AS varchar(5)) + ':' + DATENAME(mi,AggTimedate) AS [SPEND TIME]FROM(SELECTt.EID,sum(case when t.Remarks = 'LATE' then 1 else 0 end) as LATE,sum(case when t.Remarks = 'HALF DAY' then 1 else 0 end) as [HALF DAY],case when datediff(dd,'20130101','20130131')%7 < 6 then 1 else 0 end as [OFF DAY],case when datediff(dd,'20130101','20130131')%7 < 6 then 1 else 0 end as Absent, DATEADD(mi,SUM(DATEDIFF(mi,0,spendtime)),0) AS AggTimedate,convert(Varchar(10),DATEADD(hh,SUM(DATEDIFF(mi,0,excessshort)),0),108)AS [EXCESS / SHORT],case when (540 - 560) > 0 then 'Short'when (540 - 560) < 0 then 'Excess'else NULL end as ExcessShortFROM ATTEND_LOG tleft join employee e on e.eid = t.eidLEFT OUTER JOIN FRoaster (17074) T3 ON e.EID = T3.EID AND DATEPART(YYYY,T.DATE) = T3.Year AND DATEPART(MM,T.DATE) = T3.Month AND DATEPART(DD,T.DATE) = T3.DayLEFT OUTER JOIN ShiftView T4 ON T3.SName = T4.Shiftwhere t.eid=17074 and T.date >'20130101' and T.date <'20130131'group by t.eid)teid----------late--halfday--absent--offday----excess/short-excessshort------spendtime17074------1------1-------1--------1----------17:00:00------Excess------204:35i have a problem absent and off day i not showing correctly |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-27 : 06:44:39
|
Dont expect any responses until you explain us clearly with some sample data on how your table data are and on what basis you want Absent and offday value to come. Nobody will be able to make out your exact requirement from what you posted so far!------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
immad
Posting Yak Master
230 Posts |
Posted - 2013-06-27 : 07:16:56
|
just copt nad paste it into sql servercreate TABLE atend_log(eid int,date datetime,timein datetime,timeout datetime,spendtime datetime,excessshort datetime,remarks varchar(50))insert [dbo].[atend_log] ([eid],[date],[timein],[timeout],[spendtime],excessshort,[remarks])values(1,'2013-01-01 00:00:00.000','2013-06-19 08:39:00.000','2013-06-19 18:04:00.000','1900-01-01 09:25:00.000','1900-01-01 00:25:00.000','Late')insert [dbo].[atend_log] ([eid],[date],[timein],[timeout],[spendtime],excessshort,[remarks])values(1,'2013-01-02 00:00:00.000','2013-06-19 08:42:00.000','2013-06-19 09:56:00.000','1900-01-01 08:50:00.000','1900-01-01 00:10:00.000','')insert [dbo].[atend_log] ([eid],[date],[timein],[timeout],[spendtime],excessshort,[remarks])values(1,'2013-01-02 00:00:00.000','2013-06-19 10:09:00.000','2013-06-19 12:23:00.000','','','')insert [dbo].[atend_log] ([eid],[date],[timein],[timeout],[spendtime],excessshort,[remarks])values(1,'2013-01-02 00:00:00.000','2013-06-19 12:32:00.000','2013-06-19 13:14:00.000','','','')insert [dbo].[atend_log] ([eid],[date],[timein],[timeout],[spendtime],excessshort,[remarks])values(1,'2013-01-02 00:00:00.000','2013-06-19 13:30:00.000','2013-06-19 18:10:00.000','','','')insert [dbo].[atend_log] ([eid],[date],[timein],[timeout],[spendtime],excessshort,[remarks])values(1,'2013-01-03 00:00:00.000','2013-06-19 08:40:00.000','2013-06-19 17:55:00.000','1900-01-01 09:15:00.000','1900-01-01 00:15:00.000','Halfday')insert [dbo].[atend_log] ([eid],[date],[timein],[timeout],[spendtime],excessshort,[remarks])values(1,'2013-01-04 00:00:00.000','2013-06-19 08:32:00.000','2013-06-19 10:53:00.000','1900-01-01 08:45:00.000','1900-01-01 00:15:00.000','')insert [dbo].[atend_log] ([eid],[date],[timein],[timeout],[spendtime],excessshort,[remarks])values(1,'2013-01-04 00:00:00.000','2013-06-19 11:09:00.000','2013-06-19 12:57:00.000','','','')insert [dbo].[atend_log] ([eid],[date],[timein],[timeout],[spendtime],excessshort,[remarks])values(1,'2013-01-04 00:00:00.000','2013-06-19 13:06:00.000','2013-06-19 13:18:00.000','','','')insert [dbo].[atend_log] ([eid],[date],[timein],[timeout],[spendtime],excessshort,[remarks])values(1,'2013-01-04 00:00:00.000','2013-06-19 13:45:00.000','2013-06-19 18:09:00.000','','','')insert [dbo].[atend_log] ([eid],[date],[timein],[timeout],[spendtime],excessshort,[remarks])values(1,'2013-01-05 00:00:00.000','2013-06-19 08:47:00.000','2013-06-19 18:01:00.000','1900-01-01 09:14:00.000','1900-01-01 00:14:00.000','')insert [dbo].[atend_log] ([eid],[date],[timein],[timeout],[spendtime],excessshort,[remarks])values(1,'2013-01-08 00:00:00.000','2013-06-19 08:35:00.000','2013-06-19 18:29:00.000','1900-01-01 09:54:00.000','1900-01-01 00:54:00.000','')u cant see that jan 6 and jan 7 data becouse jan 6 is sunday and jan 7 is employee is absenti want to take a jan 6 and jan 7 data i try it but its give me wrong resulti hope u get it what u wantimmad uddin ahmed |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-27 : 07:23:55
|
so where do you store those absent days? or do you atleast have a calendar table?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
immad
Posting Yak Master
230 Posts |
Posted - 2013-06-27 : 07:41:53
|
yes i have a calendar table and in this calendar table i have all dates of from january 1 2013 to december 31 2013this calendar table name is calendari dont store absent days and off daysimmad uddin ahmed |
 |
|
|
|
|