Hi,
I have defined two variables as follows:
currentBeginDate := TO_date(ADD_MONTHS(LAST_DAY(ADD_MONTHS(sysdate, -1)),-1)+1, 'YYYY-MM-DD');
currentEndDate := TO_date(LAST_DAY(ADD_MONTHS(sysdate,-1)), 'YYYY-MM-DD');
testbegindate := to_date('2006-10-01','YYYY-MM-DD');
testenddate := to_date('2006-10-31','YYYY-MM-DD');
All the above are defined as varchar2(20).
I am running a query in a procedure, which has SELECT statements as follows:
1 SELECT COUNT(USER) INTO totalNewUserCount FROM UP_USER
WHERE DATE_CREATED BETWEEN testBeginDate AND testEndDate
AND CUSTOMERTYPE <> 'A';
2 SELECT COUNT(USER) INTO totalNewUserCount FROM UP_USER
WHERE DATE_CREATED BETWEEN to_date('2006-10-01','YYYY-MM-DD') AND to_date('2006-10-31','YYYY-MM-DD')
AND CUSTOMERTYPE <> 'A';
3 SELECT COUNT(USER) INTO totalNewUserCount FROM UP_USER
WHERE DATE_CREATED BETWEEN currentBeginDate AND currentEndDate
AND CUSTOMERTYPE <> 'A';
SELECT statements 1 and 2 above produce the correct result whereas the 3rd SELECT statement provide an incorrect result. I beleive this is because of the way the date is formatted. Unfortunately, I want the correct result using the 3rd option or an equivalent of the option (Crystal Report wants the date to be in this format.
Any idea how I should rewrite the definition of the variables currentBeginDate and currentendDate same as testbegindate and testenddate?
Any suggestion would be highly appreciated.
Thanks and regards,
Chandra
I have defined two variables as follows:
currentBeginDate := TO_date(ADD_MONTHS(LAST_DAY(ADD_MONTHS(sysdate, -1)),-1)+1, 'YYYY-MM-DD');
currentEndDate := TO_date(LAST_DAY(ADD_MONTHS(sysdate,-1)), 'YYYY-MM-DD');
testbegindate := to_date('2006-10-01','YYYY-MM-DD');
testenddate := to_date('2006-10-31','YYYY-MM-DD');
All the above are defined as varchar2(20).
I am running a query in a procedure, which has SELECT statements as follows:
1 SELECT COUNT(USER) INTO totalNewUserCount FROM UP_USER
WHERE DATE_CREATED BETWEEN testBeginDate AND testEndDate
AND CUSTOMERTYPE <> 'A';
2 SELECT COUNT(USER) INTO totalNewUserCount FROM UP_USER
WHERE DATE_CREATED BETWEEN to_date('2006-10-01','YYYY-MM-DD') AND to_date('2006-10-31','YYYY-MM-DD')
AND CUSTOMERTYPE <> 'A';
3 SELECT COUNT(USER) INTO totalNewUserCount FROM UP_USER
WHERE DATE_CREATED BETWEEN currentBeginDate AND currentEndDate
AND CUSTOMERTYPE <> 'A';
SELECT statements 1 and 2 above produce the correct result whereas the 3rd SELECT statement provide an incorrect result. I beleive this is because of the way the date is formatted. Unfortunately, I want the correct result using the 3rd option or an equivalent of the option (Crystal Report wants the date to be in this format.
Any idea how I should rewrite the definition of the variables currentBeginDate and currentendDate same as testbegindate and testenddate?
Any suggestion would be highly appreciated.
Thanks and regards,
Chandra