0

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
1
  • You should always aim to provide a minimal reproducible example with sample data and desired results - this provides clarity, and ensures your question is complete and working. Commented Mar 16, 2022 at 3:04

1 Answer 1

3

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'));
Sign up to request clarification or add additional context in comments.

2 Comments

This doesn't get my actives just the terminated
This is real employee data thats why I didn't provide and If I select * from tblEmpl where estatus ='A' it gives me all the active employees it seem to me the only thing it's finding is the the tdate>='2022-02-14'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.