Home > front end >  Query with multiple conditions
Query with multiple conditions

Time:03-16

I'm trying to select from a SQL query that gives me all the active employees and the terminated employees that's been terminated 30 days ago?

My table is tblEmpl and my estatus= 'A' is the employee status for active and 'T' for terminated

and the tdate = termdate

select *
from tblEmpl
where estatus = 'A' and estatus = 'T' and tdate >= '2022-02-14';

This doesn't work.

Data:

Name Estatus TermDate Work
Bill A CAR
Jill I CAR
Dill T 2022-02-24 CAR
PHil T 2022-02-14 CAR

CodePudding user response:

Your logic as described requires an OR of the estatuses, not an AND, but an AND with tdate and estatus 'T' e.g.

select *
from tblEmpl
where (estatus = 'A' or (estatus = 'T' and tdate >= '2022-02-14'));
  • Related