员工加入和离开日期之间的Sql [英] Sql for between joining and leaving date of employee
问题描述
我有一个加入两次的员工。请查看下表。
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屋!