Search between dates in 2 columns of the same table

Asked

Viewed 29 times

0

Colleagues.

I have a table that brings the beginning and the end of an event.

InicioEvento = 2016-06-01 07:00:00 
FimEvento = 2016-12-31 00:00:00

I know if I use BETWEEN, I can search between dates, but how would I do between dates with two columns? I tried that way, but I don’t know if it’s right:

select * from eventos where  (inicio_eventos BETWEEN '2016-02-22 00:00:00' and '2016-12-31 00:00:00') and  (fim_eventos BETWEEN '2016-02-22 00:00:00' and '2016-12-31 00:00:00')

1 answer

2


You should choose one of the columns to be compared, or if you want to include both, you could use "AND" in the comparison.

Where <campo_sql_1> Between InicioEvento AND FimEvento
  And <campo_sql_2> Between InicioEvento AND FimEvento

Browser other questions tagged

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