We help IT Professionals succeed at work.
Get Started

TSQL - Loop finances Items to payments

82 Views
Last Modified: 2015-07-20
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
Comment
Watch Question
Senior DBA
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019
Commented:
This problem has been solved!
Unlock 2 Answers and 3 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE