Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

SQL Query Help

$
0
0

I'm trying to get a SQL query down, and can't seem to figure out the right syntax.

First entry goes in with a new InvoiceKey and a negative amount. Second entry goes in with the same InvoiceKey and a corresponding positive amount. I need to filter out all the records with matching amounts and only show the negative amounts WITHOUT that positive record removing it from the account.

One catch is... On occasion the second entry will be done with multiple records. So if the first entry was -1000.00, removing it from the account could be done in two 500.00 entries.

This is where I'm currently at (I know it's still simple), but I know it's not right... Anyone want to help steer me in the right direction? I'm pretty sure I'll need to join the Payments table to itself and use that to compare?

SELECT * FROM Payments
WHERE AcctNo = '213000' AND...


Viewing all articles
Browse latest Browse all 4871

Trending Articles