Click here to Skip to main content
14,177,020 members
Rate this:
 
Please Sign up or sign in to vote.
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 26-Feb-19 21:01pm
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
   

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.190526.1 | Last Updated 27 Feb 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100