PDA

View Full Version : SQL Query: Multiple WHERE statements?


mattboy_slim
04-23-2003, 03:40 PM
OK, what I'd like, in theory, is to have multiple WHERE statements.

To show what I mean, I'll explain my problem:
------------
I currently have a database of events, some events span mutiple weeks, which start and end in different months. Right now I have a query which finds events that occur in January. My problem is, I can either find events that begin in January, or that end in January. My database has fields for date start, and for date end.

Right now, I have 2 conflicting events. 1 of them starts in December and ends in January. The other starts in January and ends in February. Right now, my SQL query looks like such:


"Select * from t_events where ev_dt_start BETWEEN '1/1/2004' AND '1/31/2004'


So since I'm grabbing the events that START in January, I'm only getting one of my events. If I change the where statement to ev_dt_end I only get the other event.

Thanks guys, the help is appreciated.

Matt

Spudhead
04-23-2003, 05:24 PM
I don't think I get it :rolleyes:

Do you mean something like:

"Select * from t_events where (ev_dt_start BETWEEN '1/1/2004' AND '1/31/2004') OR (ev_dt_end BETWEEN '1/1/2004' AND '1/31/2004')

... which should, in theory, get everything where the start or end date is in January. Is that what you want?

mattboy_slim
04-23-2003, 05:25 PM
Yes, that's what I mean, let me give it a shot.

mattboy_slim
04-23-2003, 05:28 PM
By George, that did it. Perfect man, perfect. Thanks.

Spudhead
04-23-2003, 05:31 PM
By Jove, that's quite alright :thumbsup: