Reputation: 97
I am using sql to write up a query in which I am trying to choose records that have their date_from column (of type date/time) that satisfy these conditions:
Here's what i've tried ..
Select name, surname
FROM employees emp
where month(emp.date_from) IN ('06' , '07' , '08', '09')
I have also tried using CASE but failed. Any help please?
Upvotes: 1
Views: 2364
Reputation: 9
SELECT firstname,
lastname,
dateofbirth
FROM patient
WHERE Day(dateofbirth) >= CASE
WHEN Month(dateofbirth) = '06' THEN 15
END
OR Month(dateofbirth) IN ( '07', '08', '09' )
ORDER BY Month(dateofbirth)
Upvotes: -1
Reputation: 44316
Sqlserver 2012
SELECT
*
FROM
employees
WHERE
DateFromParts(2000,month(date_from),day(date_from))
between '2000-06-15' and '2000-09-30'
Year 2000 is chosen because it is leap year and will handle leap year issues around 2000-02-29.
Upvotes: 0
Reputation: 13110
WHERE MONTH(emp.date_from) IN (7,8,9)
OR (MONTH(emp.date_from) = 6 AND DAY(emp.date_from) >= 15);
UPDATE
Or as dates are treated as strings in MySQL
WHERE RIGHT(emp.date_from, 5) BETWEEN '06-15' AND '09-30';
I don't know which would perform better however.
Upvotes: 3