员工加入和离开日期之间的Sql [英] Sql for between joining and leaving date of employee

查看:79
本文介绍了员工加入和离开日期之间的Sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个加入两次的员工。请查看下表。



 EmpID EmpName DateOFJoin DateOfLeaving Status 
1 XYZ 2015-10-01 2017-09-26非活跃
2 ABC 2018-01-01有效
3 XYZ 2018-10-15有效




我想输出像For Instance,我有FromDate和ToDate像'2019-12-01'和'2019-12-31'

< pre lang =text> EmpID EmpName DateOFJoin DateOfLeaving Status
2 ABC 2018-01-01 Active
3 XYZ 2018-10-15 Active





如果我有 FromDate ToDate '2017 -08-01''2017-09-30'



< pre lang =text> EmpID EmpName DateOFJoin DateOfLeaving Status
1 XYZ 2015-10-01 2017-09-26 De-Active





如果我有 FromDate ToDate '2018-01-01''2018- 03-31'



 EmpID EmpName DateOFJoin DateOfLeaving Status 
2 ABC 2018-01- 01活跃









我的尝试:



请帮助为它准备SQL。

解决方案

试试这个:



  SELECT  EmpID,EmpName,DateOFJoin,DateOfLeaving,Status 
< span class =code-keyword> FROM YourTable
WHERE (DateOFJoin BETWEEN @ FromDate AND @ ToDate )<跨班=code-keyword> OR (DateOfLeaving BETWEEN @ FromDate AND @ ToDate





其中:

@FromDate @ToDate 是传递给查询的参数。


I have one Employee who has joining two time.Please review below table.

EmpID    EmpName    DateOFJoin    DateOfLeaving    Status
1         XYZ       2015-10-01    2017-09-26       De-Active
2         ABC       2018-01-01                     Active                      
3         XYZ       2018-10-15                     Active



I want output like For Instance, I have FromDate and ToDate like '2019-12-01' and '2019-12-31'

EmpID    EmpName    DateOFJoin    DateOfLeaving    Status
2         ABC       2018-01-01                     Active 
3         XYZ       2018-10-15                     Active



IF I have FromDate and ToDate like '2017-08-01' and '2017-09-30'

EmpID    EmpName    DateOFJoin    DateOfLeaving    Status
1         XYZ       2015-10-01    2017-09-26       De-Active



IF I have FromDate and ToDate like '2018-01-01' and '2018-03-31'

EmpID    EmpName    DateOFJoin    DateOfLeaving    Status
2         ABC       2018-01-01                     Active





What I have tried:

Please Help to prepare SQL For it.

解决方案

Try this:

SELECT EmpID, EmpName, DateOFJoin, DateOfLeaving, Status
FROM YourTable
WHERE (DateOFJoin BETWEEN @FromDate AND @ToDate) OR (DateOfLeaving BETWEEN @FromDate AND @ToDate)



Where:
@FromDate And @ToDate are arguments passed into a query.


这篇关于员工加入和离开日期之间的Sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆