I hope this is not a deception of another question, but I could not see it anywhere - it is also a simplified version of another question that I asked , I hope that I will begin to work on how to approach it.
I am looking to work out consistent payment ranges when there is at least one payment in each month.
I have the following data examples
CREATE TABLE
(
Contact_reference NVARCHAR(55)
,Date_payment DATETIME
,Payment_value MONEY
)
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
And what I would like to do is to develop for each contact the ranges by which they were given sequentially (defined as providing at least once in each calendar month), the number of consecutive payments, the total value for each (and ideally, if possible, the gap between the current range and the end of the very last).
:
CREATE TABLE
(
contact_reference NVARCHAR(55)
,Range_start DATETIME
,Range_end DATETIME
,Payments INT
,Value MONEY
,months_until_next_payment INT
)
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
INSERT INTO
, , , :)