insert into ta_tbl_TempLeaveViewdetails(Employee_Code_ID,LeaveType,Leave_Name,Leave_FromDate,Leave_ToDate,NumberOfDays,Reason)
select distinct
T.Employee_Code_ID,T.LeaveType,T.Leave_Name,T.Leave_FromDate,T.Leave_ToDate,T.NumberOfDays,T.Reason
from ta_tbl_TempLeaveView T  left join ta_tbl_TempLeaveViewdetails S on T.Employee_Code_ID=S.Employee_Code_ID and T.LeaveType=S.LeaveType and T.Leave_Name=S.Leave_Name and T.Leave_FromDate=S.Leave_FromDate and T.NumberOfDays=T.NumberOfDays and T.Reason=S.Reason where S.Employee_Code_ID is null and T.Leave_FromDate<=cast(getdate() as date)
select * from ta_tbl_TempLeaveViewdetails