I have a table like :

```
EmpId , LeaveDays, StartDate,       EndDate
------------------------------------------------------
1    , 4        , 24-Jan-2016,     27-Jan-2016
2    , 4        , 26-Jan-2016,     29-Jan-2016
1    , 3        , 15-Jan-2016,     17-Jan-2016

```

i am working on payroll report, above table is leave table. Now admin want to generate payroll report between two dates like '1 Jan 2016' to 25 Jan 2016. it will fetch 3 count for **user with Id 1**. but when admin goes to detail report there are 2 more leaves in this peroid i.e. 24, 25 jan.

I have used following query:

```
select ISNULL(sum(convert(float,NumberOfDays)),0) from table
    WHERE FromDate >= '15-Jan-2016' and EndDate <='25-Jan-2016'

```

We don't want to do this by loop. i don't want to iterate the loop for number of dates coming between fromdate and Enddate. is there any way in which we can achieve this goal. Please help me. 

**UPDATE:**
Sorry my question is bit confusing: let try to explain the things again:

We have two records for empId=1 okay?

i.e. 

```
EmpId , LeaveDays, StartDate,       EndDate
------------------------------------------------------
1    , 4        , 24-Jan-2016,     27-Jan-2016
1    , 3        , 15-Jan-2016,     17-Jan-2016

```

Now when my startdate = 24-Jan-2016 and Enddate ='28-Jan-2016'.. What my above query will return is : "**7**". Right..

Now i am chainging the enddate to "25-Jan-2016". Now what my query will return is: **3** because as per my condition it will fetch only records having date less than by passing(enddate i.e. 25-jan-2016) date. so it will fetch only **3**. 

but i want to get the result as **5**, means 3 for dates 15-17 jan and 2 for 24 and 25 th jan.

I hope my question is clear now.. :)