Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help with sum query
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00760459
Message ID:
00760466
Views:
17
Thanks Sergey! That was easy.

>You can use your previous select as derived table. See changes below
>
>>I am using a sum and group by in my query to find differences in a total field in a parent table and the child tables.
>>
>SELECT SUM(td.diff)
>  FROM (
>>select o.ytotalorder-sum(ar.yamttrans) as diff
>>from orders o inner join orderardetail ar on o.uordid=ar.uordid
>>where (ar.cartypid='II' or ar.cartypid='IM')
>>  and o.tcreate>='2002-12-18' group by o.uordid,o.ytotalorder
>>having o.ytotalorder>sum(ar.yamttrans)
>>order by o.uordid
>       ) td
>>
>>This works fine. It gives me a list of the orders that are out of balance. Now I want to get a grand total of those differences (sum the difference). Is there a way to do it in T-Sql?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform