Hi Friends,

I'm working on employee payroll using "Coldfusion" and "Mysql". I've to calculate the salary for the employee. The employee took leave for 4 days 30-07-2011 to 02-08-2011. I've given the sample table of my db.
-----------------------------------------------------------------------
Empno Name From To Total_days_Leave
-----------------------------------------------------------------------

4 x 2011-07-30 2011-08-02 4
-----------------------------------------------------------------------

What's my question is if I want to calculate the salary for 7 th month(2011-07-01 to 2011-07-31) the Total days leave taken should be '2'. what I'm getting is '4' the query is as below

SELECT * , SUM( in_ApptotLeave ) AS totLeave
FROM tb_gempleave
WHERE fkin_id = '3'
AND vc_appreason = "Approved"
AND dt_appFromDate
BETWEEN '2011-07-01'
AND '2011-09-30'
AND dt_appToDate
BETWEEN '2011-07-01'
AND '2011-07-30'
GROUP BY vc_appreason


Please guide me. Thanks in advance...