Doubtless, there are typos and bugs in the sql below. You'll probably be unable to just paste it in and have it work perfectly, but that's why I've put in all my steps. Work your way through them and let me know which ones don't work and why and I'll try to fix them.
First, try this just to get the cumulative Qty:
SELECT Trans1.sID AS sID,
Trans1.Qty AS Qty,
(SELECT SUM(Trans2.Qty) FROM Tran AS Trans2 WHERE Trans2.tDate<=Trans1.tDate AND Trans1.sID=Trans2.sID) AS [sum]
FROM Tran AS Trans1
WHERE Trans1.sID = 584;
That should give
sID | Qty | sum
----+-----+----
584 | 5 | 5
584 | 4 | 9
If that works, we should be able to break the Qty out by type:
SELECT Trans1.sID AS sID,
Trans1.Qty AS Qty,
Trans1.tType AS tType,
(SELECT SUM(Trans2.Qty) FROM Tran AS Trans2 WHERE Trans2.tDate<=Trans1.tDate AND Trans1.sID=Trans2.sID AND Trans2.tType=1) AS deposits,
(SELECT SUM(Trans2.Qty) FROM Tran AS Trans2 WHERE Trans2.tDate<=Trans1.tDate AND Trans1.sID=Trans2.sID AND Trans2.tType=1) AS purchases,
(SELECT SUM(Trans2.Qty) FROM Tran AS Trans2 WHERE Trans2.tDate<=Trans1.tDate AND Trans1.sID=Trans2.sID AND Trans2.tType=3) AS sales
FROM Tran AS Trans1
WHERE Trans1.sID = 584;
Since both transactions are type 2 in your example, that should give
sID | Qty | tType | deposits | purchases | sales
----+-----+-------+----------+-----------+------
584 | 5 | 2 | 0 | 5 | 0
584 | 4 | 2 | 0 | 9 | 0
Now let's try joining the two tables together. I'll join by sID and date, and use a RIGHT JOIN so that all of the dates and prices are included.
SELECT SPrices.pDate AS pDate,
SPrices.sID AS sID,
Trans1.Qty AS Qty,
Trans1.tType AS tType,
SPrices.lPr AS lPr
FROM Tran AS Trans1
RIGHT JOIN SPrices ON Trans1.sID = SPrices.sID AND Trans1.tDate=SPrices.pDate
WHERE SPrices.sID = 584;
This should give a row for every row in SPrices for sID 584, with transactions listed on the appropriate days and NULL rows otherwyse:
pDate | sID | Qty | tType | lPr
-----------+-----+------+-------+------
09/07/2012 | 584 | 5 | 2 | 69.99
10/07/2012 | 584 | NULL | NULL | 69.87
...
26/07/2012 | 584 | NULL | NULL | 72.40
27/07/2012 | 584 | 4 | 2 | 71.20
28/07/2012 | 584 | NULL | NULL | 72.20
Okay, if that's good, we'll add the two pieces together (the cumulative sums and the join). I've changed the cumulative sums to use SPrices.pDate, since we want the cumulative sum for each day, regardless if there's a transaction that day:
SELECT SPrices.pDate AS pDate,
SPrices.sID AS sID
Trans1.Qty AS Qty,
Trans1.tType AS tType,
SPrices.lPr AS lPr,
(SELECT SUM(Trans2.Qty) FROM Tran AS Trans2 WHERE Trans2.tDate<=SPrices.pDate AND SPrices.sID=Trans2.sID AND Trans2.tType=1) AS deposits,
(SELECT SUM(Trans2.Qty) FROM Tran AS Trans2 WHERE Trans2.tDate<=SPrices.pDate AND SPrices.sID=Trans2.sID AND Trans2.tType=1) AS purchases,
(SELECT SUM(Trans2.Qty) FROM Tran AS Trans2 WHERE Trans2.tDate<=SPrices.pDate AND SPrices.sID=Trans2.sID AND Trans2.tType=3) AS sales
FROM Tran AS Trans1
RIGHT JOIN SPrices ON Trans1.sID = SPrices.sID AND Trans1.tDate=SPrices.pDate
WHERE SPrices.sID = 584;
pDate | sID | Qty | tType | lPr | deposits | purchases | sales
-----------+-----+------+-------+-------+----------+-----------+------
09/07/2012 | 584 | 5 | 2 | 69.99 | 0 | 5 | 0
10/07/2012 | 584 | NULL | NULL | 69.87 | 0 | 5 | 0
...
26/07/2012 | 584 | NULL | NULL | 72.40 | 0 | 5 | 0
27/07/2012 | 584 | 4 | 2 | 71.20 | 0 | 9 | 0
28/07/2012 | 584 | NULL | NULL | 72.20 | 0 | 9 | 0
Finally, I'm going to wrap the whole thing in another select just to do the value calculation. I'm also going to drop the columns we don't actually need.
SELECT
pDate,
sID,
lPr,
deposits,
purchases,
sales,
lPr * (IFNULL(deposits, 0) + IFNULL(purchases,0) - IFNULL(sales,0)) AS [Value]
FROM (
SELECT SPrices.pDate AS pDate,
SPrices.sID AS sID,
SPrices.lPr AS lPr,
(SELECT SUM(Trans2.Qty) FROM Tran AS Trans2 WHERE Trans2.tDate<=SPrices.pDate AND SPrices.sID=Trans2.sID AND Trans2.tType=1) AS deposits,
(SELECT SUM(Trans2.Qty) FROM Tran AS Trans2 WHERE Trans2.tDate<=SPrices.pDate AND SPrices.sID=Trans2.sID AND Trans2.tType=1) AS purchases,
(SELECT SUM(Trans2.Qty) FROM Tran AS Trans2 WHERE Trans2.tDate<=SPrices.pDate AND SPrices.sID=Trans2.sID AND Trans2.tType=3) AS sales
FROM Tran AS Trans1
RIGHT JOIN SPrices ON Trans1.sID = SPrices.sID AND Trans1.tDate=SPrices.pDate
WHERE SPrices.sID = 584
) AS t;
The final result is:
pDate | sID | lPr | deposits | purchases | sales | Value
-----------+-----+-------+----------+-----------+-------+------
09/07/2012 | 584 | 69.99 | 0 | 5 | 0 | 349.95
10/07/2012 | 584 | 69.87 | 0 | 5 | 0 | 349.34
...
26/07/2012 | 584 | 72.40 | 0 | 5 | 0 | 362.00
27/07/2012 | 584 | 71.20 | 0 | 9 | 0 | 640.80
28/07/2012 | 584 | 72.20 | 0 | 9 | 0 | 649.80