K
K
Kirill2018-11-22 22:31:21
Transact SQL
Kirill, 2018-11-22 22:31:21

How to create a stored procedure for filling one table with data from another using loops?

There is a table of the following form containing the contract number, the contract conclusion date, its end date and the quantity of goods:
ContractID INT, StartDate DATETIME, EndDate DATETIME, Qty INT
23232323233, 02/15/14, 08/18/15, 1400
...
It is necessary to create a procedure that will take new data from the table above and add to another table in the following form:
ContractID INT, Period DATETIME, QtyDev INT
23232323233, 02/01/14, 100
23232323233, 03/01/14, 100
23232323233, 04/01/14, 100
...
That is evenly distribute the quantity of goods over the entire duration of the contract. I am looking for someone who can help me with the task and explain how to do it. Willing to pay for your work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2018-11-23
@tsklab

You have an error: 02/01/2014 is not included in the period that starts on 02/15/2014 . And what is the difficulty: divide the number by the number of months? Yes, there will be difficulty with rounding, but this issue has already been resolved: How to round percentages correctly?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question