Qry Help | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Qry Help

The qry lists all open Fail trades from x Fails table grouped by CNo and AccNo. The Pair off report displays all open tags that can be paired off against each other for the same security by quantity. This is the case when the client bought and decided to sell out; hence the trades result in perfect matches. CODs are matched against COR or FTR and CORs are matched against COD or FTD. It display the all open tags that can be paried off against each other for the same security by quantity. sample data
AcNo CNo Type Qty
70-30000-00030382NAC8COR126238.0 i havte written like this
Select a.AccN0 ,
a.CNo ,
NetQty=Sum(a.Qty )+ Sum(b.Qty* -1 )
From x a ,
x b
Where a.AccNo = b.AccNo and
a.CNo = b.CNo and
a.Type in (‘COD’,’FTR’) and
b.Type in (‘COR’,’FTD’)
Group by a.AccNo, a.CNo
Having Sum(a.Qty)+ Sum(b.qty* -1) = 0 Desc: i want select Cno,Accno and calculate net quantity grouped by cno,accno..if netqty is zero..records should display based on above conditions Im not sure this qry is correct…can u pl let me know any ther way
Is your query working? Do you have any other Types besides COD, FTR, COR, and FTD because it doesn’t reflect in your sample data? Also, what are you trying to achieve with NetQty=Sum(a.Qty )+ Sum(b.Qty* -1 ), especially what is NetQty .. is it an alias to the summed values? Try this; it is a simplified version of what I think you are trying to achieve:
SELECT AccNO, CNo, (SUM(Qty)+ SUM(Qty*-1)) AS NetQty
GROUP BY AccNo, CNo, Qty
HAVING SUM(Qty)+ SUM(Qty* -1) = 0 Let me know if it works. – Tahsin