CREATE PROCEDURE AbsenteeReportPersonCount(
    @customer_param INT,
    @person_param INT,
    @from_param DATETIME,
    @to_param DATETIME,
    @day_start_param INT)
AS
BEGIN
    DECLARE @customerparam INT, @personparam INT, @fromparam DATETIME, @toparam DATETIME, @daystartparam TIME;
    DECLARE @qry NVARCHAR(4000);
    SET @daystartparam = CONVERT(TIME, DATEADD(SECOND,@day_start_param,0));
    SET @fromparam = @from_param;
    SET @toparam = DATEADD(SECOND,86399,@to_param);
    SET @customerparam= @customer_param;
    SET @personparam = @person_param;

    SET @qry = 'SELECT
    COUNT(PC.cloud_date)
FROM
    person PA CROSS JOIN cloud_date_table PC
WHERE
        PA.customer_id = @customerparam AND PA.person_id = @personparam
    AND PA.is_deleted = 0
    AND PC.cloud_date BETWEEN @fromparam AND @toparam ';

    DECLARE @statement NVARCHAR(4000);
    SET @statement = @qry;
    DECLARE @parameterDefinition NVARCHAR(4000);
    SET @parameterDefinition = N'@customerparam INT, @personparam INT, @fromparam DATETIME, @toparam DATETIME, @daystartparam TIME';
    EXEC sp_executesql @statement,@parameterDefinition,@customerparam=@customerparam,@personparam=@personparam,@fromparam=@fromparam,@toparam=@toparam,@daystartparam=@daystartparam;

END;

--Testcases
-- EXEC AbsenteeReportPersonCount 1,1,'2018-12-01', '2018-12-30', 0