Good day community.
I need to make a query in SQL (Sql Server 2012) to filter by a range of dates (Start Date - Term Date).
The table is as follows:
DETENTIONS
ID
ESTADO
EQUIPO
FECHAINICIO
FECHATERMINO
The Problem, is that sometimes the Field FECHATERMINO
can be NULL
which is because it is still "stopped" to date according to my business logic .
SELECT * FROM DETENCIONES WHERE EQUIPO=1
AND @FECHA >= FECHAINICIO AND @FECHA <= FECHATERMINO
I already tried with an OR but it returns all the EQUIPMENT that has a NULL on its end date, that is, it does not respect the parentheses.
SELECT * FROM DETENCIONES WHERE EQUIPO=@EQUIPO
AND @FECHA >= FECHAINICIO AND (@FECHA <= FECHATERMINO OR FECHATERMINO=NULL)
PS: I visualize the data in a Website created with ASP.NET C #.