SQL Query Filter by date range
Hello guys i hope you can help me in my problem.
i have this data
DateFrom DateTo
---------- ----------
2018-01-01 2018-01-01
2018-01-02 2018-01-02
2018-01-04 2018-01-04
2018-01-07 2018-01-07
2018-01-10 2018-01-10
2018-01-14 2018-01-14
2018-01-17 2018-01-17
2018-01-18 2018-01-18
2018-01-20 2018-01-20
2018-01-23 2018-01-23
2018-01-26 2018-01-26
2018-01-30 2018-01-30
2018-02-01 2028-12-31
the data i want to check if exists is date from 2025-01-01 to 2025-01-31
i made this query it works fine
(CONVERT(date, DateFrom) <= @DateTo AND CONVERT(date, DateTo) >= @DateFrom)
but when i have this data
DateFrom DateTo
---------- ----------
2024-12-10 2024-12-10
2024-12-11 2024-12-11
2024-12-12 2024-12-12
2024-12-14 2028-12-31
the data 2024-12-14 2028-12-31 was showing in the query.
thanks
i have this data
DateFrom DateTo
---------- ----------
2018-01-01 2018-01-01
2018-01-02 2018-01-02
2018-01-04 2018-01-04
2018-01-07 2018-01-07
2018-01-10 2018-01-10
2018-01-14 2018-01-14
2018-01-17 2018-01-17
2018-01-18 2018-01-18
2018-01-20 2018-01-20
2018-01-23 2018-01-23
2018-01-26 2018-01-26
2018-01-30 2018-01-30
2018-02-01 2028-12-31
the data i want to check if exists is date from 2025-01-01 to 2025-01-31
i made this query it works fine
(CONVERT(date, DateFrom) <= @DateTo AND CONVERT(date, DateTo) >= @DateFrom)
but when i have this data
DateFrom DateTo
---------- ----------
2024-12-10 2024-12-10
2024-12-11 2024-12-11
2024-12-12 2024-12-12
2024-12-14 2028-12-31
the data 2024-12-14 2028-12-31 was showing in the query.
thanks