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
Microsoft SQL ServerMicrosoft SQL Server 2008SQL

Avatar of undefined
Last Comment
Amour22015

8/22/2022 - Mon
SOLUTION
ste5an

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Scott Pletcher

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Amour22015

ASKER
Great thanks
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy