Click here to Skip to main content
15,074,464 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Posted
Updated 18-Sep-21 22:22pm
v2

1 solution

Try this:

SQL
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.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900