I have one doubt in sql server
get records based on installments
Table :productdetails

```
CREATE TABLE [dbo].[productdetails](
    [productid] [int] NULL,
    [Productrstartdate] [date] NULL,
    [Productenddate] [date] NULL,
    [EMIInstallment] [int] NULL
) ON [PRIMARY]
GO
INSERT [dbo].[productdetails] ([productid], [Productrstartdate], [Productenddate], [EMIInstallment]) VALUES (1, CAST(N'2020-10-02' AS Date), CAST(N'2024-10-02' AS Date), 5)
GO
INSERT [dbo].[productdetails] ([productid], [Productrstartdate], [Productenddate], [EMIInstallment]) VALUES (2, CAST(N'2020-02-10' AS Date), CAST(N'2021-02-10' AS Date), 2)
GO
INSERT [dbo].[productdetails] ([productid], [Productrstartdate], [Productenddate], [EMIInstallment]) VALUES (3, CAST(N'2019-01-10' AS Date), CAST(N'2019-01-10' AS Date), 1)
GO
INSERT [dbo].[productdetails] ([productid], [Productrstartdate], [Productenddate], [EMIInstallment]) VALUES (4, CAST(N'2019-01-18' AS Date), CAST(N'2021-01-18' AS Date), 3)
GO

```

based on above data i want output like below

```
Productid |Installmentdate  |noofinstallmentcount
1         |2020-10-02       |1
1         |2021-10-02       |2
1         |2022-10-02       |3
1         |2023-10-02       |4
1         |2024-10-02       |5
2         |2020-02-10       |1
2         |2021-02-10       |2
3         |2019-01-10       |1
4         |2019-01-18       |1
4         |2020-01-18       |2
4         |2021-01-18       |3

```

i tried like below :

```
DECLARE @MINDATE DATE='2019-01-18'
DECLARE @COUNT INT=10
dECLARE @MAXDATE DATE='2024-10-02'

;WITH ABC
AS 
(
SELECT  productid ,@MINDATE CalendarDate ,1 as id from [dbo].[productdetails]
UNION ALL
SELECT a.productid ,DATEADD(YEAR,1,a.Productrstartdate ), 1 FROM  [dbo].[productdetails] a
join  [dbo].[productdetails]  b on a.productid=b.productid
 WHERE   @MINDATE <@MAXDATE     ) 
 SELECT * FROM ABC 

```

above query not given expected output

could you please tell me how to write query to achive this task in sql server .