I have a problem with Sum fields in Crystal Reports, under VS 2003. I am using VS 2003 and Crystal Reports to generate a report with data retrieved from a SQL Server 2000 database and kept during runtime inside a strongly typed dataset.
The dataset contains several tables, one of which, the orders table, receives the results of a SQL query, that joins records from two different tables. After checking the contents of the orders table during runtime - just before passing the dataset to the Report object, I have verified that the SQL query in question is working correctly, always returning the expected data from the database.
The dataset is iterated over, each iteration merging the results of the SQL query, executed against a different orderID, into the dataset. The SQL query also retrieves records from other tables related to each orderID, and puts them into the appropriate tables (other than orders) in the dataset.
The problem appears when I try to sum a particular column, the orders.order_amount column, onto a Crystal Report. The sum I get is incorrect.
For example, the orders table contains 3 records at the time it is bound as the report's datasource, each with an order_amount = $10.00. Instead of returning $30.00, the value of the sum field is something like $50.00.
I can't see how this could happen, I assume that this is either due to a bug in Crystal Reports, or a result of a missing item from my report. The dataset is correctly populated, but it appears that Crystal Reports somehow confuses the related records retrieved based on the orderIDs as being records of the orders table, and adds to the order_amount sum.
If I disable the SELECT statement that populates the related records, the order_amount sum is shown correctly.
Anybody got any idea as to why this happens? Thanks in advance.
Ray