Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7417503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:42:52+00:00 2026-05-29T07:42:52+00:00

i am trying to write a procedure that inserts rows into a temp table.

  • 0

i am trying to write a procedure that inserts rows into a temp table. the basis of the table is an insurance policy table listing the amount of the premium earned over the life of the policys. the original data consists of the trans_date (date sold) and the policy_start and policy_end dates. i.e. if the policy is 12 months long, we give each month 1/12 of the premium collected.

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 completely baffled at the moment)

My problem is that i need to create the extra 11 rows of data and modify the transaction date to add 1 month each time until the modified transaction date = policy_end date.

i’ve researched using a CTE, but while loops aren’t posible within a CTE..

is this something a multistatement table function could do?

Many thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:42:52+00:00Added an answer on May 29, 2026 at 7:42 am

    You can defo do this with a CTE, for example this little snippet will demonstrate how to do recursion using dates:

    declare @start DATETIME = '2012-02-01'
    declare @end DATETIME = '2013-02-01'
    ;with cte (date)
    AS
    (
        SELECT @start
        UNION ALL
        SELECT DATEADD(mm,1,cte.date)
        FROM cte WHERE DATEADD(mm,1,cte.date)<@end
    )
    select * from cte
    

    That will generate a list of dates between @start & @end with month gaps.

    You can

    1. Use your real tables in place of the dummy dates
    2. Perform an insert into...select ... from cte to insert your required data

    If you can provide more detail about your table schema, I can probably help out with a more concrete example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a stored procedure that inserts a row into an
I'm trying to write a stored procedure that will read an Excel file into
I am trying to write a stored procedure that takes a table name as
I'm trying to write a stored procedure in SQL that will : Make a
I'm trying to write a stored procedure to select employees who have birthdays that
I am trying to write a stored procedure which selects columns from a table
I am trying to write a stored procedure that will allow me to write
I'm trying to write a stored procedure that will have 6 bit value flags
I am trying to write a procedure that will fire the same select query
I'm currently trying to write a stored procedure that can compute the biweekly periods

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.