May 29, 2020 at 10:56 am
Hello,
I have query contains both start and end date, i would like to filter out data based on two dates. I need only 2019 and higher data either based on start or end date, if you can have a look examples. i need ID 1,2,3,6,7 and 4,5 is not required. I have tried using Year function on both dates, but like to know any other easy solution for this.
CREATE TABLE #TEMP
(
ID INT,
SDate DATE,
EDate DATE
)
INSERT INTO #TEMP
SELECT 1,'01/01/2014', '01/01/2019'
UNION ALL
SELECT 2,'01/01/2015', '01/01/2020'
UNION ALL
SELECT 3,'01/01/2019', '12/31/2019'
UNION ALL
SELECT 4,'01/01/2012', '12/31/2018'
UNION ALL
SELECT 5,'01/01/2010', '10/01/2016'
UNION ALL
SELECT 6,'06/01/2020', '10/01/2020'
UNION ALL
SELECT 7,'01/01/2021', '03/01/2021'
May 29, 2020 at 11:46 am
I imagine you want your WHERE clause to be something like this:
WHERE SDate > '20190101'
AND EDate > '20190101'
May 29, 2020 at 11:54 am
Start date is not relevant ... at least based on the sample data provided.
SELECT *
FROM #TEMP t
WHERE t.EDate >= '20190101';
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply