Reputation: 62
So I have a lot of data which is stock adjustments, some are gains and some are losses.
I need to find all the records which net to £0.
They are from multiple locations.
I have data like this:
Store Code Product Code. Adjust Cost
AA1 12345. £20
AA1 12345. -£20
AA1. 12345. £40
AAB 45567. £14
AAB 43256. -£14
I also have a field which concats Store Code and Product Code to create a unique value to each store that has adjusted that code.
From the data above I will be looking to select only these records
AA1 12345. £20
AA1 12345. -£20
Thanks in advance for any help.
Upvotes: 0
Views: 39
Reputation: 32682
This should do the trick:
SELECT * FROM MyTable t
WHERE (SELECT Sum(i.[Adjust Cost]) FROM MyTable i WHERE i.[Store Code] = t.[Store Code]) = 0
Upvotes: 1