Share via

Descrepancy between SalesLT.SalesOrderDetail and SalesLT.SalesOrderHeader?

Jasper Versteegh 45 Reputation points
2025-12-10T14:31:19.0566667+00:00

I deployed a new AdventureWorks LT. When I query:

select * from SalesLT.SalesOrderDetail where salesorderID = 71774

there's 2 rows: SalesOrderDetailID's 110562 and 110563. They both have a linetotal of 356.898000 so when I query:

select sum(LineTotal) from SalesLT.SalesOrderDetail where salesOrderID = 71774

the result equals 713.796000.

However, on the headers:

select * from SalesLT.SalesOrderHeader where salesorderID = 71774

The subtotal is 880.3484. 880.3484 + TaxAmt 70.4279 + Freight 22.0087 = TotalDue 972.785.

But why is 880.3484 not equal to the 713.796000? There's no Tax on the lines, there's no discount, there's no deductions. How was this designed in the demodb?

SQL Server | SQL Server Transact-SQL

Answer accepted by question author

Erland Sommarskog 134.1K Reputation points MVP Volunteer Moderator
2025-12-10T21:54:48.7833333+00:00

I don't have that particular flavour of AdventureWorks, and the AdventureWorks databases I have, sum of LineTotal appears to match SubTotal for all orders, at least within the currency unit in question.

There is a moral here of database design: The column SubTotal is redundant, and with redundant columns there is always risk that you get inconsistencies due to bugs, because someone forgot to update the header table. (And here I have a production scenario in mind, not a demo database, where the reason for the inconsistency may be sheer sloppiness.)

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.