Hello all,
I'm having trouble getting my user defined function operating properly. I am running on SQL Server 2000.
I am trying to return a table of all users that have an even balance in a "BillingTransactions" table. Our transactions are specified by the RecordType field; 0 for purchase, 1 for payment. So what I'm trying to do is get a list of all users where the sum of each transaction with RecordType 0 equals the sum of each transaction with RecordType 1. This is what the internal portion of my function looks like now:
SELECT DISTINCT UserName FROM BillingTransactions
WHERE (SELECT SUM(AMOUNT)
FROM BillingTransactions
WHERE [BillingTransactions].[RecordType]= 0
AND
[BillingTransactions].[UserName]= UserName)
=
(SELECT SUM(AMOUNT)
FROM BillingTransactions
WHERE [BillingTransactions].[RecordType]= 1
AND
[BillingTransactions].[UserName]= UserName)
I have a feeling this is not the most efficient way to do this... Is there any other way you can see how to go about this? Thanks!