根据年度月份计算员工当前正在工作(活动emp)和员工数量目前不工作(InActive emp)

编程入门 行业动态 更新时间:2024-10-27 22:33:39
本文介绍了根据年度月份计算员工当前正在工作(活动emp)和员工数量目前不工作(InActive emp)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

请任何人帮助我 我在表中有一个表名作为Empmaster我有列Emp_Joinindate,Emp_leavingdate,Emp_Status 我的问题是 假设 该公司在2012年1月雇用了100名员工 和2012年9月50名员工离开公司 和2012年10月再次公司雇用了25名新员工 这里我正在通过月份和年份我希望显示这些数据,例如有多少员工目前正在工作(Active Emp)以及如何许多员工在一年中的特定月份离开公司 假设我通过月份= jan和year = 2012 PresentWorkingEmp = 100且leftEmp = 0 假设如果通过月份= sept且年份= 2012 PresentWorkingEmp = 50且leftEmp = 50 假设如果通过月份= 10月和年份= 2012 PresentWorkingEmp = 75且leftEmp = 0因为(在月份公司雇用了2个月) 5所以50 + 25 = 75 leftEmp = 0) 请任何人帮助我

解决方案

试试这个。如果您已发布样本数据。

声明 @ m varchar ( 2 ), @ y varchar ( 4 ) set @ m = ' 08' set @ y = 2012 DECLARE @ date DATETIME SELECT @ date = convert ( datetime , @ m + ' - 01 ' + ' - ' + @ y ) - select @date SELECT @ date = DATEADD(d,-1,DATEADD(m,DATEDIFF(m, 0 , @ date )+ 1 , 0 )) 声明 @Empmaster table ( Emp_Joinindate datetime ,Emp_leavingdate datetime ,Emp_Status varchar ( 2 )) insert @Empmaster 值(' 04 -01 -2012',' 05-01-2012',' 1') insert @Empmaster 值(' 04-01-2012', NULL ,' 1') insert @Empmaster 值(' 05-01-2012', null ,' 1') insert @Empmaster 值(' 05-01-2012',' 07-01-2012',' 1') insert @Empmaster 值(' 06-01-2012', null ,' 1') insert @Empmaster 值(' 07-01-2012 ', null ,' 1') //活跃的emp 选择 * 来自 @Empmaster 其中 Emp_Joinindate< = @ date 和(ISNULL (Emp_leavingdate,' 12-31-9999'))> = @ date // Emp left 选择 * 来自 @Empmaster 其中 Emp_Joinindate< = @ date 和(ISNULL(Emp_leavingdate,' 12-31-9999'))< = @ date

你也可以尝试这个

SELECT SUM( CASE WHEN Emp_Status = 1 AND datepart(MONTH,[Emp_Joinindate])= DATEPART(月,GETDATE() ) AND datepart(YEAR,[Emp_Joinindate])= DATEPART(年,GETDATE()) AND Emp_LeftDate IS NULL 那么 1 ELSE 0 END ) as WorkingEmp, SUM( CASE WHEN Emp_Status = 0 AND datepart( MONTH,[Emp_Joinindate])= DATEPART(月,GETDATE()) AND datepart(年,[Emp_Joinindate])= DATEPART(年,GETDATE()) AND Emp_Lef tDate IS NOT NULL THEN 1 ELSE 0 END ) as LeftEmployee, 来自 EmployeeMaster

对于正在工作的员工我假设他们的离职日期显然是空的 选择*来自Empmaster,其中Emp_LeavindDate为空 和DatePart(mm,EmpJoinInDate)='数字中的月份参数' 和DatePart(yy,EmpJoinInDate)='年数参数此处数字' 对于已经离开的员工我假设他们的离职日期显然不是空的 选择*来自Empmaster Emp_LeavindDate不为空的地方 和DatePart(mm,EmpLeavingDate)='数字中的月份参数' 和DatePart(yy,EmpLeavingDate)='年份参数此处在数字

Please can any one help me I have one table name as Empmaster in that table i have columns Emp_Joinindate ,Emp_leavingdate,Emp_Status my question is Suppose the company hired 100 employee in the month of January 2012 and September 2012 50 employee left from the company and October 2012 again company hired 25 new employees here i am passing month and year soo i want show this data like how many employee presently working (Active Emp)and and how many Employee left the company on particular month of year suppose if i pass month=jan and year =2012 PresentWorkingEmp=100 and leftEmp=0 suppose if pass month=sept and year =2012 PresentWorkingEmp=50 and leftEmp=50 suppose if pass month=October and year =2012 PresentWorkingEmp=75 and leftEmp=0 because (in month oct company hired 25 so 50+25=75 leftEmp=0) please can any one help me

解决方案

Try this. If you have post the sample data.

declare @m varchar(2), @y varchar(4) set @m = '08' set @y=2012 DECLARE @date DATETIME SELECT @date = convert(datetime, @m + '-01' + '-' + @y) --select @date SELECT @date=DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, @date) + 1, 0)) declare @Empmaster table ( Emp_Joinindate datetime,Emp_leavingdate datetime,Emp_Status varchar(2) ) insert @Empmaster values ('04-01-2012','05-01-2012','1') insert @Empmaster values ('04-01-2012',NULL,'1') insert @Empmaster values ('05-01-2012',null,'1') insert @Empmaster values ('05-01-2012','07-01-2012','1') insert @Empmaster values ('06-01-2012',null,'1') insert @Empmaster values ('07-01-2012',null,'1') //Active emp select * from @Empmaster where Emp_Joinindate <= @date and (ISNULL(Emp_leavingdate,'12-31-9999')) >= @date // Emp left select * from @Empmaster where Emp_Joinindate <= @date and (ISNULL(Emp_leavingdate,'12-31-9999')) <= @date

You can try this one too

SELECT SUM(CASE WHEN Emp_Status = 1 AND datepart(MONTH,[Emp_Joinindate]) = DATEPART(Month,GETDATE()) AND datepart(YEAR,[Emp_Joinindate]) = DATEPART(YEAR,GETDATE()) AND Emp_LeftDate IS NULL THEN 1 ELSE 0 END) as WorkingEmp , SUM(CASE WHEN Emp_Status = 0 AND datepart(MONTH,[Emp_Joinindate]) = DATEPART(Month,GETDATE()) AND datepart(YEAR,[Emp_Joinindate]) = DATEPART(YEAR,GETDATE()) AND Emp_LeftDate IS NOT NULL THEN 1 ELSE 0 END) as LeftEmployee , from EmployeeMaster

For Employees Who Are Working I am assuming That Their Leaving Date Is Null Obviously Select * From Empmaster Where Emp_LeavindDate Is Null And DatePart(mm,EmpJoinInDate) = 'MONTH PARAMETER HERE In Numeric' And DatePart(yy,EmpJoinInDate) = 'YEAR MONTH PARAMETER HERE In Numeric' For Employees Who Have Left I am assuming That Their Leaving Date Is Not Null Obviously Select * From Empmaster Where Emp_LeavindDate Is Not Null And DatePart(mm,EmpLeavingDate) = 'MONTH PARAMETER HERE In Numeric' And DatePart(yy,EmpLeavingDate) = 'YEAR MONTH PARAMETER HERE In Numeric'

更多推荐

根据年度月份计算员工当前正在工作(活动emp)和员工数量目前不工作(InActive emp)

本文发布于:2023-06-02 07:59:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/440284.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:员工   工作   数量   年度   InActive

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!