Do i simplified your query? I'm not sure... ;)
DECLARE @product TABLE (prtID INT IDENTITY(1,1), prtQty INT)
INSERT INTO @product (prtQty)
SELECT 1
UNION ALL SELECT 4
UNION ALL SELECT 4
DECLARE @stockInOut TABLE (IOID INT IDENTITY(1,1), prtType VARCHAR(2), prtID INT, IOQty INT, IODate DATETIME)
INSERT INTO @stockInOut (prtType, prtID, IOQty, IODate)
SELECT 'I', 1, 6, '2013-08-07'
UNION ALL SELECT 'O', 2, 1, '2013-08-08'
UNION ALL SELECT 'O', 1, 1, '2013-08-08'
DECLARE @sell TABLE (sellID INT IDENTITY(1,1), prtID INT, sellQty INT, sellDate DATETIME)
INSERT INTO @sell (prtID, sellQty, sellDate)
SELECT 1, 2, '2013-08-05'
UNION ALL SELECT 2, 2, '2013-08-10'
DECLARE @reject TABLE (rejID INT IDENTITY(1,1), prtID INT, rejQty INT, sellDate DATETIME)
INSERT INTO @reject (prtID, rejQty, sellDate)
SELECT 1, 1, '2013-08-09'
UNION ALL SELECT 2, 1, '2013-08-10'
SELECT prtID, SUM(Balance) AS Balance
FROM (
SELECT prtID, MAX(prtQty) + MAX(IQty) - MAX(COALESCE(OQty,0)) - MAX(COALESCE(sellQty,0)) - MAX(COALESCE(rejQty,0)) AS Balance
FROM (
SELECT P.prtID, P.prtQty, CASE WHEN SIO.prtType = 'I' THEN SIO.IOQty ELSE 0 END AS IQty,
CASE WHEN SIO.prtType = 'O' THEN SIO.IOQty ELSE 0 END AS OQty, S.sellQty, R.rejQty, SIO.IODate
FROM @product AS P
LEFT JOIN @stockInOut AS SIO ON P.prtID = SIO.prtID
LEFT JOIN @sell AS S ON S.prtID = SIO.prtID
LEFT JOIN @reject AS R ON R.prtID = SIO.prtID
) AS T
WHERE IODate BETWEEN '2013-08-01' AND '2013-08-31' OR IODate IS NULL
GROUP BY prtID
) AS D
GROUP BY prtID
ORDER BY prtID
Result:
prtID Balance
1 3
2 0
3 4