It is not clear what your problem is. Submit some test data and the results you would like to have.
I only noticed that the in the where clause
(DateSignup BETWEEN '2010-11-1' AND '2010-12-1' AND PaymentCycle = "1") OR ((DateSignup BETWEEN '2010-11-1' AND '2010-12-1' AND PaymentCycle = "12")
you are duplicating the DateSignup conditon which might lead to erroneous coding. I'd rather code: ((DateSignup BETWEEN '2010-11-1' AND '2010-12-1') AND (PaymentCycle = "1" OR PaymentCycle = "12"))
smantscheff
Nearly a Posting Virtuoso
1,233 posts since Oct 2010
Reputation Points: 300
Solved Threads: 254
Test data would really help.
If I understand you correct, the WHERE condition would change to:
((DateSignup BETWEEN '2010-11-1' AND '2010-12-1') AND (PaymentCycle = "1" OR PaymentCycle = "12"))
OR
((DateSignup < '2010-01-01') AND (PaymentCycle = "12"))
smantscheff
Nearly a Posting Virtuoso
1,233 posts since Oct 2010
Reputation Points: 300
Solved Threads: 254
If you are not able to prepare some test data - which do not have to be your actual customer's data - you should go back to square 1 and try again.
Apart from that your WHERE clause is quite unreadable. I doubt that even you fully understand what you are doing there.
Bracket your AND and OR clause to avoid logical errors.
Your WHERE clause
(DateSignup BETWEEN '2010-11-01' AND '2010-12-01' OR PaymentCycle = "1" AND DateSignup <= '2010-12-01')
OR
(PaymentCycle = "12" AND
(YEAR(DateSignup) < YEAR('2010-11-01')
AND YEAR(DateSignup) < YEAR('2010-12-01')
AND MONTH(DateSignup) >= MONTH('2010-11-01')
AND MONTH(DateSignup) <= MONTH('2010-12-1')
AND DAY(DateSignup) BETWEEN DAY('2010-11-01')
AND DAY('2010-12-01')
))
can be recoded as ( (DateSignup BETWEEN '2010-11-01' AND '2010-12-01')
OR
(PaymentCycle = "1" AND DateSignup <= '2010-12-01')
)
OR
(PaymentCycle = "12" AND
(YEAR(DateSignup) < 2010
AND YEAR(DateSignup) < 2010
AND MONTH(DateSignup) >= 11
AND MONTH(DateSignup) <= 12
AND DAY(DateSignup) BETWEEN 1 AND 1
))
which is obviously nonsense.
So prepare some test data and we'll see how we can help with that.
smantscheff
Nearly a Posting Virtuoso
1,233 posts since Oct 2010
Reputation Points: 300
Solved Threads: 254