How to get current month details in from date to todate wise in sql
My query:
select a.Staff_Id as StaffID,a.From_Date,upper(b.Staff_Name) as StaffName,a.From_Date
,a.To_Date,a.Total_Days as TotalDays,Convert(Varchar(24),
Applied_Date,113) as Applied,a.Reason as Reason,Status=(case a.Status when 'I' then 'Applied' when 'A'then 'Approved' when 'R' then 'Rejected' when 'C' then 'Cancelled' else a.status end),Done_By =(select upper(staff_name) from Accounts_Emp_Master emp where emp.staff_id = Done_by),Convert(Varchar(11),Done_Date,106)
as DoneDate from Accounts_LeaveEntry_New a,Accounts_Emp_Master b where a.Staff_Id = b.Staff_Id
AND (('2014-12-01' <= a.From_Date And '2014-12-01' >= a.To_Date) or ('2014-12-01' >=a.From_Date and '2014-12-01' <= a.To_Date))
and (b.Department = 3) order by a.From_Date asc
above query wise
First Check:
(('2014-12-01' <= a.From_Date And '2014-12-01' >= a.To_Date) or ('2014-12-01' >=a.From_Date and '2014-12-01' <= a.To_Date)) this date wise above query check Last month record came
ex:
StaffID StaffName Fromdate ToDate TotalDays AppliedDate
1059 T T SIVAM 29-Nov-14 7-Dec-14 7 24-Nov-14
1029 ROY CHOUDURY P K 1-Dec-14 31-Jan-15 54 13-Nov-14
I want result is (december)month first date record only
StaffID StaffName Fromdate ToDate TotalDays AppliedDate
1029 ROY CHOUDURY P K 1-Dec-14 31-Jan-15 54 13-Nov-14