January 9, 2008 at 5:23 am
Hi, I've got 2 queries, that basically do the same thing, but require a different date range, I'd liek to know how to combine them.
its like this:
Query A:
select x from tablea
where
z = 1
and startdate > '2007-12-31'
and startdate < '2008-02-01'
Query B:
select x from tablea
where
z = 0
and startdate > '2008-01-31'
and startdate < '2008-03-01'
So depending upon whether z is 1 or 0 alters the date range I use.
Any help much appreciated.
January 9, 2008 at 6:38 am
Can you explain what you mean by combine? Run both of them together? Run one of them based on Z?
January 9, 2008 at 6:43 am
sorry, yes.
I'd like to get both sets of results but only using 1 query
so like:
select a
from tablea
where
if z=0
and startdate > '2008-01-31'
and startdate < '2008-03-01'
else if z=1
and startdate > '2007-12-31'
and startdate < '2008-02-01'
endif
is that sort of thing possible?
January 9, 2008 at 6:47 am
Try just simply using an OR:
select a
from tablea
where
(
z=0
and startdate > '2008-01-31'
and startdate < '2008-03-01'
)
OR
(
z=1
and startdate > '2007-12-31'
and startdate < '2008-02-01'
)
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
January 9, 2008 at 6:53 am
of course.
I feel such a fool.
couldn't see the wood for trees.
🙂
January 9, 2008 at 6:57 am
It's early - grab some more caffeine - the fog will disperse soon:)
I have weeks like that too!
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply