TSQL: Dates that lie between (intersect) with and by date?

Can someone give me tsql to find also the dates that lie inside the cottage to date.

select * from empc where
DateFrom >= p_todate AND DateTo <= p_todate

I mean that the gaps between them should also be captured (I don't want to use the BETWEEN syntax)

please, help

+3
source share
2 answers

If you need to select all ranges that intersect a given range:

SELECT  *
FROM    empc
WHERE   DateFrom <= p_todate
        AND DateTo >= p_fromdate
+2
source

Or you can use between:

SELECT  *
FROM    empc
WHERE   DateFrom BETWEEN p_fromdate AND p_todate

This gives you an exhaustive range.

+2
source

Source: https://habr.com/ru/post/1745964/


All Articles