Question: If a user win Puzzle Game Level than I make a Toast "You Win Play Next Level" and then I want to show rewarded video ads.

What code will be there to show Admob Rewarded Video Ads after Toast in android studio?

```
    if (isSolved())
        Toast.makeText(context, "You Win ! Play Next Level", Toast.LENGTH_LONG).show();

```

Answer: 
The following SQL seems to work. I have assumed that the Employee is valid up to, but not on, the ValidTo date to avoid double counting on these dates when the ValidFrom and ValidTo overlap; you'll need to amend the INNER JOIN logic if this assumption is incorrect.

```
    --Get the min and max dates in the employee table
DECLARE @todate date, @fromdate date
SELECT @fromdate= min(ValidFrom) from [POC].[dbo].[EmployeeSCD2];
SELECT @todate= max(validto) from [POC].[dbo].[EmployeeSCD2];

-- Generate a list of all the dates between the two dates
WITH calendar (FromDate) AS (
    SELECT @fromdate AS FromDate
    UNION ALL
    SELECT DATEADD(day, 1, FromDate)
    FROM Calendar
    WHERE FromDate < @todate
)
-- Join the list of dates to the employee table - gives a record per date per employee active on that date
SELECT CAL.FromDate, COUNT(EMP.EMPLOYEENO) 'Employee Count' 
FROM CALENDAR CAL
INNER JOIN [POC].[dbo].[EmployeeSCD2] EMP ON CAL.FromDate >= EMP.ValidFrom AND CAL.FromDate < EMP.ValidTo
group by cal.FromDate
OPTION (MAXRECURSION 0) -- Without this parameter the recursion stops after 100 loops
;

```
An easy ways is to build a date table and then count how many employee (or customer) were in that particular date.

```
;with t as (   -- this is your table/Dimension
    select pk,EmployeeNo,Building,ValidFrom,ValidTo 
    from (values (1, 1, 'a', '2000-01-01', '2008-06-01'),
                 (2, 1, 'b', '2008-06-01', '2010-06-01'),
                 (3, 1, 'c', '2010-06-01', '2011-08-01'),
                 (4, 2, 'a', '2000-01-01', '2008-06-01'),
                 (5, 2, 'b', '2008-06-01', '2010-06-01'),
                 (6, 2, 'c', '2010-06-01', '2011-08-01')
        )t (pk,EmployeeNo,Building,ValidFrom,ValidTo)
)
, dates as ( -- this is a recursive query, building a date table from 2000-01-01 up to today
    select convert(date, '2000-01-01') as d
    union all
    select DATEADD(d,1,d) 
    from dates 
    where d < getdate()-1
)
select d.d, count(1) as [Employe count]  
from dates d
inner join t on d.d between t.ValidFrom and t.ValidTo -- will join only valid employee
group by d.d 
option (maxrecursion 0)  -- since our dates table recurse over more than 100 times and the dataset is fairly small, you need this option

```