I have a table with this entries:
StartDate | EndDate
2016-01-06 | 2016-01-16
2016-01-06 | 2016-01-16
2016-01-06 | 2016-01-16
2016-01-06 | 2016-01-16
2016-01-06 | 2016-01-16
2016-01-06 | 2016-01-16
2016-01-06 | 2016-01-16
2016-01-06 | 2016-01-16
2016-01-06 | 2016-01-16
2016-01-06 | 2016-01-16
2016-01-06 | 2016-01-16
2016-01-06 | 2016-01-16
2016-01-06 | 2016-01-16
2016-01-06 | 2016-01-16
2016-01-07 | 2016-01-17
2016-01-07 | 2016-01-17
2016-01-07 | 2016-01-17
2016-01-07 | 2016-01-17
2016-01-07 | 2016-01-17
2016-01-07 | 2016-01-17
2016-01-07 | 2016-01-17
2016-01-07 | 2016-01-17
2016-01-08 | 2016-01-18
2016-01-08 | 2016-01-18
2017-01-01 | 2017-01-10
2026-01-06 | 2026-01-16
2026-01-07 | 2026-01-17
And my query in stored procedure is:
SELECT ROW_NUMBER() OVER ( ORDER BY [StartDate] ASC) as ROWNUM, [Oid]
From [dbo].[Ument]
Where (
(@StartDate is null or StartDate >= @StartDate)
or (@EndDate is null or EndDate <= @EndDate)
)
I want to search by @StartDate
written by user or, if is null/empty, by @StartDate >= today
's date.
But, at the same time, I want to search by @endDate
, written by user or, if is null/empty, EndDate >= today
's.
If today's is between two dates, i need to return it.
Like this:
@startDate isn't null? YES: use the @startDate written by user to filter startDate >= @StartDate. NO: use today's date to put startDate >= today.
@endDate isn't null? YES: use the @endDate written by user to filter endDate <= @endDate NO: use max-date (e.g.: 2050/12/31) to filter endDate <= max-Date