Conditions different from the same column

Asked

Viewed 59 times

2

I have a table called anuncios:

id | nome   | finalizar | datafim
1  | teste1 | N         | 0000-00-00
2  | teste2 | S         | 2018-12-05

I’d like to make a SELECT listing only records where the column value finalizar be it N or that is S, as long as it’s S, to datafim is less than or equal to today.

1 answer

0


You can use the following instruction:

SELECT * 
  FROM anuncios
 WHERE (finalizar = 'N' OR (finalizar = 'S' AND datafim <= GETDATE()))
  • Hello. It didn’t work. Returned the following error: Fatal error: Uncaught Error: Call to a Member Function fetch() on Boolean

  • Are you running on sql server or mysql? I ran the test on SQL Server and it works. You can enter the types of each field or specific in the "finish"?

  • It worked out here. obg

Browser other questions tagged

You are not signed in. Login or sign up in order to post.