I am trying to write a procedure that inserts rows into a temp table. the table is based on a table of insurance policies indicating the amount of premium received during the term of the policy. The source data consists of trans_date (date of sale) and the dates policy_start and policy_end. those. if the policy is valid for 12 months, we provide 1/12 of the premium every month.
so something like
while trans_month < policy_end month insert to tblUEPtmp select dateadd(mm, 1, trans_date), earned_premium from tblpolicys set trans_date = dateadd(mm, 1, trans_date)
(I know this is rubbush code, but I'm currently completely baffled)
My problem is that I need to create an additional 11 rows of data and change the transaction date to add 1 month every time before the date of the transaction change date = policy_end.
I researched the use of CTE, but while loops do not fit in CTE ..
- is it something that could fulfill the function of a table of several elements?
Many thanks.
source share