I have difficulties to write a T-SQL script to return required result.
Here is my data:
And the required result is like this:
Here is my Oracle script for this result:
CREATE TABLE t
(
contract_no VARCHAR2(100),
begin_date DATE,
end_date DATE
);
INSERT INTO t VALUES ('AAA',to_date('22-12-2020','DD-MM-YYYY'),to_date('13-05-2021','DD-MM-YYYY'));
INSERT INTO t VALUES ('BBB',to_date('20-03-2019','DD-MM-YYYY'),to_date('01-06-2019','DD-MM-YYYY'));
SELECT *
FROM t;
select contract_no
, begin_date
, end_date
, l
, last_day(add_months(trunc(begin_date,'MONTH'),l-1))
from t, lateral (select level l
from dual
connect by level <= round(months_between(last_day(end_date),trunc(begin_date,'MONTH')))-1);
I need the equivalent script in T-SQL.
Thanks in advance