Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i need to put those two output values (Add_sum and Minus_sum) to one table and subtract them (Add_sum - Minus-sum) and show this value




SELECT        I.ItemCode, COUNT(H.TransactionTypeID) AS ADD_Sum
FROM            inMoveHd AS H INNER JOIN
                         inMoveLn AS L ON L.InvMoveID = H.InvMoveID INNER JOIN
                         inItem AS I ON I.ItemID = L.ItemID INNER JOIN
                         inTransactionType AS T ON H.TransactionTypeID = T.TransactionTypeID
WHERE        (T.TransactionSign = 1)
GROUP BY I.ItemCode'

'

SELECT        I.ItemCode, COUNT(H.TransactionTypeID) AS Minus_Sum
FROM            inMoveHd AS H INNER JOIN
                         inMoveLn AS L ON L.InvMoveID = H.InvMoveID INNER JOIN
                         inItem AS I ON I.ItemID = L.ItemID INNER JOIN
                         inTransactionType AS T ON H.TransactionTypeID = T.TransactionTypeID
WHERE        (T.TransactionSign = -1)
GROUP BY I.ItemCode'
<pre>


What I have tried:

I tried many other options , subqueries etc but could not get it to work
Posted
Updated 30-Oct-19 23:05pm

1 solution

ok , ive got it

SELECT  I.ItemCode,
        COUNT(case when T.TransactionSign = 1 then H.TransactionTypeID end) AS ADD_Sum,
        COUNT(case when T.TransactionSign = -1 then H.TransactionTypeID end) AS Minus_Sum
FROM      inMoveHd AS H INNER JOIN
                   inMoveLn AS L ON L.InvMoveID = H.InvMoveID INNER JOIN
                   inItem AS I ON I.ItemID = L.ItemID INNER JOIN
                   inTransactionType AS T ON H.TransactionTypeID = T.TransactionTypeID
WHERE  (T.TransactionSign = -1 or T.TransactionSign = 1)
GROUP BY I.ItemCode
 
Share this answer
 
Comments
Richard Deeming 31-Oct-19 9:22am    
Posting a question and then immediately posting the answer suggests that you already knew the answer when you posted the question, and the only reason you posted at all was to get the "rep points" for posting the solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900