Hello,
I have a query that returns some transactions I have to look at:
select t.tradeID, ABS(t.volume) as totalVolume, ABS(tr.volume) as
partialVolume, t.symbol
from transactions tr, trades t
where tr.tradeID = t.tradeID AND (tr.isMatched = 0 OR tr.isMatched IS NULL)
Sample Data:
tradeID totalVolume partialVolume Symbol
247 4000 2000 ABC
247 4000 1000 ABC
247 4000 500 ABC
247 4000 500 ABC
248 2000 1000 XYZ
248 2000 1500 XYZ
What I want to do is that add the particalVolume column up to give me the
values 4000 and 1500 in this case.
SO far what I have.
Create Table #tempTable
(
ID numeric
)
INSERT INTO #tempTable Select transactionID from transactions where moniker
IS NULL
declare @.partialVolume int
set @.partialVolume = 0
declare @.tempTradeID int
WHILE Exists(Select ID from #tempTable)
begin
Select @.partialVolume = (volume from transactions Where tradeID = @.tempTradeID + @.partialVolume
END
It doesn't work.For those curious.
I got this to work using the SUM function.
Here is the SQL statement.
select t.tradeID, t.symbol, tr.[transaction], t.volume, sum(tr.volume),
t.accountNumber
from transactions tr, trades t
where tr.symbol = t.symbol AND LEFT(tr.[transaction], 1) =LEFT(t.[transaction], 1) AND tr.date = t.date AND tr.moniker is NULL
group by t.tradeid, t.symbol, tr.[transaction], t.volume, t.accountNumber
"Won Lee" <noemail> wrote in message
news:%23Ytzp90aDHA.2932@.tk2msftngp13.phx.gbl...
> Hello,
> I have a query that returns some transactions I have to look at:
> select t.tradeID, ABS(t.volume) as totalVolume, ABS(tr.volume) as
> partialVolume, t.symbol
> from transactions tr, trades t
> where tr.tradeID = t.tradeID AND (tr.isMatched = 0 OR tr.isMatched IS
NULL)
> Sample Data:
> tradeID totalVolume partialVolume Symbol
> 247 4000 2000 ABC
> 247 4000 1000 ABC
> 247 4000 500 ABC
> 247 4000 500 ABC
> 248 2000 1000 XYZ
> 248 2000 1500 XYZ
>
> What I want to do is that add the particalVolume column up to give me the
> values 4000 and 1500 in this case.
> SO far what I have.
> Create Table #tempTable
> (
> ID numeric
> )
> INSERT INTO #tempTable Select transactionID from transactions where
moniker
> IS NULL
> declare @.partialVolume int
> set @.partialVolume = 0
> declare @.tempTradeID int
> WHILE Exists(Select ID from #tempTable)
> begin
> Select @.partialVolume = (volume from transactions Where tradeID => @.tempTradeID + @.partialVolume
>
> END
> It doesn't work.
>
No comments:
Post a Comment