第一张表First table which sync with machine,这是第二张表Once data is inserted it will invoke the trigger and inserted into second table
朋友们可以帮我解决这个问题......
我写了下面的查询,但无法计算正确的休息时间。
alter procedure sp_get_Attendance_salary_report
@name varchar(500),
@lname varchar(500),
@fromDate varchar(500),
@toDate varchar(500),
@eid varchar(500)
as
begin
declare @sqlcommand varchar(8000);
set @sqlcommand='select
te.EmployeeId as [Employee Id],
(te.name+'' ''+te.lname) Names,
tsom.Shiftdate as [ShiftDate],
datename(dw,tsom.Shiftdate) as [Week Day],
convert(varchar(50),tsom.InTime,109) as [In time],
convert(varchar(50),tsom.OutTime,109) as [Out Time],
convert(varchar(5),(Convert(time,tsom.OutTime - tsom.InTime ,8)),8)as [Total Working Hours],
shift_hours
into #temp_time
from dbo.tbl_emp_shift_ot_mapping tsom
inner join tblEmployee te on te.EmployeeId=tsom.emp_id
inner join tbl_shift_timing tst on tst.id=tsom.shift_id
where tsom.emp_id<>convert(int,'''')'
if(@name <> '' )
begin
set @sqlCommand = @sqlCommand + ' and te.name like ''%'+@name+'%'''
end
if( @lname <> ' ')
begin
set @sqlCommand = @sqlCommand + ' and te.lname like ''%'+ @lname+'%'' '
end
if (@todate <> '') and ( @fromDate <>'' )
begin
set @sqlCommand = @sqlCommand + ' and tsom.shiftdate >= CONVERT(date,'''+@fromDate+''',104) and tsom.shiftdate <= CONVERT(date,'''+@todate+''',104) '
end
if(@eid <> 0 )
begin
set @sqlCommand = @sqlCommand + ' and te.employeeId = '''+@eid+''''
end
set @sqlCommand = @sqlCommand +' order by tsom.InTime desc';
set @sqlcommand = @sqlcommand + ' select names,[Employee Id],
isnull(
RIGHT(''0'' + CAST( sum( (CAST(SUBSTRING([Total Working Hours], 1, CHARINDEX('':'', [Total Working Hours], 1)-1) AS INT)*3600+
CAST(SUBSTRING([Total Working Hours], CHARINDEX('':'', [Total Working Hours], 1)+1, 1000) AS INT)*60)) / 3600 AS VARCHAR),10) + ''.'' +
RIGHT(''0'' + CAST(( sum( (CAST(SUBSTRING([Total Working Hours], 1, CHARINDEX('':'', [Total Working Hours], 1)-1) AS INT)*3600+
CAST(SUBSTRING([Total Working Hours], CHARINDEX('':'', [Total Working Hours], 1)+1, 1000) AS INT)*60)) / 60) % 60 AS VARCHAR),2),0.00)
AS [Completed Hours],
sum(shift_hours) [Estimated Hours]
from #temp_time
group by names,[Employee Id] '
exec (@sqlCommand)
print @sqlCommand
--exec @sqlCommand
end
id User_ID Event_Trigger Time_Stamp
116203 66 IN 10/13/2016 07:07
116171 66 OUT 10/12/2016 16:24
116168 66 IN 10/12/2016 14:34
116155 66 OUT 10/12/2016 13:25
116124 66 IN 10/12/2016 06:44
116106 66 OUT 10/11/2016 16:51
116097 66 IN 10/11/2016 11:49
116096 66 OUT 10/11/2016 11:28
116078 66 IN 10/11/2016 07:17
116050 66 OUT 10/10/2016 16:25
116040 66 IN 10/10/2016 14:23
116030 66 OUT 10/10/2016 13:19
116006 66 IN 10/10/2016 07:00
115954 66 IN 10/08/2016 13:35
115899 66 OUT 10/08/2016 08:10
115878 66 IN 10/07/2016 16:18
115873 66 OUT 10/07/2016 14:21
115860 66 IN 10/07/2016 13:36
115832 66 OUT 10/07/2016 06:59
115803 66 IN 10/06/2016 16:39