SQL - Filter by range dates with double column

0

Hi, I have a problem with a query. I want to filter by date ranges with two columns. Start and End.

X | Inicio    | Fin  
1 |2018-10-01 | 2018-10-31  
2 |2018-11-01 | 2018-11-30  
3 |2018-11-15 | 2018-12-15  

Inicio BETWEEN @parametroInicial AND @parametroFinal  
AND  
Fin BETWEEN @parametroInicial AND @parametroFinal 

It has not worked for me. Simple filters like @parametroInicial < = Start either: (.

The data types of the columns and parameters are: DATETIME.

Example: in the table is the month of November, if I send the parameters' 2018-11-01 'to' 2018-11-30 'I should return the records 2 and 3 and in the same way if I send' 2018 -11-14 'to' 2018-11-16 '

The problem that I have seen is that in some filters it is limited to everything that is out of range or exclusively within the range therefore the records that its initial date is not inside, even if its final date is, they do not come out in the result.

link < - a reference image

    
asked by Roberto Rivera 23.11.2018 в 17:14
source

1 answer

1
SELECT *
        FROM tabla  A
        WHERE   @parametroFinal >= A.Inicio  AND
                A.Fin  >= @parametroInicial

This will match all the date ranges of the table and the parameters that have an intersection.

    
answered by 23.11.2018 / 18:15
source