Hi @balakrishna k ,
Please also check:
;with cte
as(select eid,paiddate,
row_number() over(partition by eid order by eid) rr,
substring(cast(cast(paiddate as date) as varchar),6,2) mm
from tempc)
,cte2 as
(select c.*
from cte c
left join cte c2 on c.rr=c2.rr-1 and c.eid=c2.eid
where cast(c2.mm as int)-cast(c.mm as int)=3)
select eid,upper(format(dateadd(MM,1,paiddate),'yyyy"-"MMM"-"dd')) paiddate,0 salry
from cte2
union
select eid,upper(format(dateadd(MM,2,paiddate),'yyyy"-"MMM"-"dd')),0
from cte2
Output:
If you have any question, please feel free to let me know.
Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.