Get records of two periods of dates (range of two dates)
SELECT MeterReadings.MeterNo,
MeterReadings.LastKWH,
MeterReadings.AccountNo,
MeterReadings.MultiplyFactor,
MeterReadings.ReadingDate,
MeterReadings.LastReading,
MeterReadings.ThisMonthReading,
MeterReadings.NumberofDays,
PeriodicConsumptions.ConsumptionKWH,
MeterReadings.ReadingGYear,
MeterReadings.ReadingGMonth
FROM MeterReadings , PeriodicConsumptions
WHERE
((MeterReadings.AccountNo =PeriodicConsumptions.AccountNo )
and (MeterReadings.ReadingGYear =PeriodicConsumptions.ConsumptionYear)
and (MeterReadings.ReadingGMonth =PeriodicConsumptions.ConsumptionMonth )
and (MeterReadings.ReadingDate = PeriodicConsumptions.FromDate )
and ((MeterReadings.ReadingGYear = 2011 and MeterReadings.ReadingGMonth >= 6 )
OR (((MeterReadings.ReadingGYear = 2012) AND (MeterReadings.ReadingGYear <= 2014))
and MeterReadings.ReadingGMonth <= 6)))
and (MeterReadings.AccountNo= '4320900010')
ORDER BY MeterReadings.ReadingDate
Result is: (for simplicity, I just put the year and month)
2011 6
2011 7
2011 8
2011 9
2011 10
2011 11
2011 12
2012 1
2012 2
2012 3
2012 4
2012 5
2012 6
As per the query, the query should display all years and months of 2011, 2012, 2013 and 2014 with the exception of year 2011 to be displayed starting from month 6 as specified and should stop at the displaying records at month 6 of year 2014.
I need to be able to display any range of two dates.
Pls, I need your help
PS: ReadingDate is saved as string type not as date type.
Thanks