Hi,
I need to create a query which extracts just
1. those members who were enrolled for at least 90 days anytime starting from Sep1,2003 till the Apr30/2004. (However they may be enrolled before Sep1 and enrollment end date migh happen before Apr 30.
2. The part of their enrollment should take place after Sept 30
I did the following query:
SELECT *
FROM mytable
WHERE DateDiff("d",[mytable].[startdtSept1],([mytable].[program end date])>=90 and DateDiff("d",[mytable].[startdtSept30],([mytable].[program end date])>0 and DateDiff("d",[mytable].[program start date],[mytable].[startdtSept1])>=0;
However I found out that some members are extracted whose: 1.program start date is 10/1/2003
2.and program end date 10/31/2003
They should not be in the file as they do not meet the conditions. As I learned before, Datediff
function assumes the earlier date goes first..but although for most of them PROGRAM END DATE is later than SEPT1....in some cases PROGRAM END DATE goes BEFORE... as well as sometimes START DATE is after SEPT1
How I can adjust my query in order it take into account such a scenario? Probably I cannot do it with DateDiff()?
I have beaten my head...and have no clue...
Could you please give me a hand? It would be greatly appreciated...
Thank you in advance
I need to create a query which extracts just
1. those members who were enrolled for at least 90 days anytime starting from Sep1,2003 till the Apr30/2004. (However they may be enrolled before Sep1 and enrollment end date migh happen before Apr 30.
2. The part of their enrollment should take place after Sept 30
I did the following query:
SELECT *
FROM mytable
WHERE DateDiff("d",[mytable].[startdtSept1],([mytable].[program end date])>=90 and DateDiff("d",[mytable].[startdtSept30],([mytable].[program end date])>0 and DateDiff("d",[mytable].[program start date],[mytable].[startdtSept1])>=0;
However I found out that some members are extracted whose: 1.program start date is 10/1/2003
2.and program end date 10/31/2003
They should not be in the file as they do not meet the conditions. As I learned before, Datediff
function assumes the earlier date goes first..but although for most of them PROGRAM END DATE is later than SEPT1....in some cases PROGRAM END DATE goes BEFORE... as well as sometimes START DATE is after SEPT1
How I can adjust my query in order it take into account such a scenario? Probably I cannot do it with DateDiff()?
I have beaten my head...and have no clue...
Could you please give me a hand? It would be greatly appreciated...
Thank you in advance