Below query is used to retrieve records from database to shown in report. But the SENOKO AND EUNOS column show duplicate total in every row. This seems the
Oh, your problem is simple. Your query is simply not correlated to the outer query, so you are getting the total for Senkoku
(and presumably EUNO
) across the entire whbal
table.
Reading your query, I figured that this was what you wanted.
I think you need a correlation clause in the subquery, where you tie the rows in whbal
to some column in one of the outer tables. Not knowing what you really want or your data structure, I can't propose a particular condition.
EDIT:
The correct way to connect them would be:
(SELECT SUM(CONVERT(DECIMAL(8,3),(CONVERT(DECIMAL(8, 3), whbal.qty_good) + CONVERT(DECIMAL(8, 3), whbal.qty_slack)) * CONVERT(DECIMAL(8, 3), whbal.std_weight) / 1000))
FROM whbal
WHERE warehouse = 'SKW' and whbal.customer = customer.customer
) AS SENOKO