Jae Jae - 4 months ago 6
SQL Question

How do I write a SQL query filter with an unless?

I have a query that is returning transactions where the paycode and task do not match. However, there are a couple paycode/task combinations that can be ignored such as "Salary"/"SalaryReg".

Is there a way to write a query that goes like:

select user, trxdate, paycode, task from TABLE
where paycode <> task
--unless when paycode = "Salary" the task = "SalaryReg"


Any suggestions would be appreciated! Thank you!

Answer
select user, trxdate, paycode, task from TABLE 
where paycode <> task 
and not
(
    (paycode = "Salary" AND task = "SalaryReg")
OR
    (paycode = "Janitorial" AND task = "Cleaning")
OR
    (paycode = "FrontDesk" AND task = "GreetingCustomers")
)
Comments