Link to home
Start Free TrialLog in
Avatar of Amour22015
Amour22015

asked on

TSQL - Loop finances Items to payments

Hi Experts,

I need a program that will loop though all the possible payments someone makes.

So I have a InvoicePayment table:
PaymentID	Payment
71	384.29
74	194.47
77	250
79	359.36
81	10.46
85	359.47
87	304.47

Open in new window


I have a InvoiceItem table:
itemID	InvoiceNr	Total
33194	74	350
47882	74	8
33195	75	10
47883	75	16.15
33196	76	295
47884	76	3.93
37960	77	445
37961	78	445
33197	79	185
33198	79	17.05
47885	79	32.3
39254	80	445
37596	81	430
33199	83	145
47886	83	4.1
33200	84	250
47887	84	30.39
33201	85	24.95
33202	85	24.95
47888	85	9.71
37962	86	430
33416	87	990
37963	88	430
39255	89	430

Open in new window


For this purpose please only for the matching:
Where InvoicePayment.paymentID = InvoiceItem.InvoiceNr

To Insert Into PaymentApplied table with colums:
ItemID, PaymentID, PaymentApplied

So this payment got applied to this itemID

If this post is confusing please say so, otherwise it looks almost like several that have been answered and I will need more clarity.

Please help and thanks
SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Amour22015
Amour22015

ASKER

Great thanks