简体   繁体   English

每月报告计算SQL中的开始时间和结束时间,不包括星期日

[英]monthly report to calculate start time and end time in SQL excluding Sunday

I have tables [Mst_Daily_Report_Pds] where I have start time and end time it calculates the date between '11-01-2016' and '11-30-2016' and the output will be displayed into graph. 我有表[Mst_Daily_Report_Pds] ,我有开始时间和结束时间,它计算'11 -01-2016'和'11 -30-2016之间的日期,输出将显示在图表中。

Ex: 例如:

8.5hrs * 7days = 59.5hrs,
8.5hrs * 6days = 51hrs 

so the percentage is 85% which is wrong data. 所以百分比是85%这是错误的数据。

My problem is it includes Sunday also which is not necessary how to exclude Sunday values? 我的问题是它包括星期日也没有必要如何排除星期日值?

Kindly check the below code: 请检查以下代码:

select Name,Actual_Hours,round((Actual_Hours/((DATEDIFF(DAY,'11-01-2016'  ,'11-30-2016')+1)*8.5))*100,0) as percentage 
from (select Name , SUM(actual_Hours) Actual_Hours  
from ( select Name,ACTUAL_HOURS=sum(DATEPART(hh,[Time_Taken_in_Min]))+sum(DATEPART(MINUTE,[Time_Taken_in_Min])) /60  
FROM [HR_Admin].[dbo].[Mst_Daily_Report_Pds]  where date between  '11-01-2016'  and  '11-30-2016'   
    GROUP BY  Name )o group by Name  )a order by Actual_Hours desc

Kindly help me to exclude the Sunday values in over all percentage. 请帮助我排除所有百分比的星期日值。

You should create #tempTable to store the date between '11-01-2016' and '11-30-2016' exclude Sunday by use @@DATEFIRST. 您应该使用@@ DATEFIRST创建#tempTable以将日期存储在'11 -01-2016'和'11 -30-2016'之间,排除星期日。 @@DATEFIRST is used to set the first day of the week to a number from 1 through 7. So the temp table will be : @@ DATEFIRST用于将一周的第一天设置为1到7之间的数字。因此临时表将是:

SELECT *  
FROM tempTable
WHERE ((DATEPART(dw, Date) + @@DATEFIRST) % 7) NOT IN (1)  

If your SQL database set Sunday is the first day of week. 如果您的SQL数据库设置为星期日是一周的第一天。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM