Monday, March 19, 2012

Nested Query (Urgent)

Folks

I have two queries

Select Account_Id , Branch_Cd from Accounts

SELECT SUM (dbo.HOLDING.Shares_Par_Value_Qty * dbo.ASSET.Current_Prc) AS MarketValue
FROM dbo.HOLDING INNER JOIN
dbo.ASSET ON dbo.HOLDING.Property_Num = dbo.ASSET.Property_Num
Group by dbo.HOLDING.Account_ID

Account_ID is the same in both the queries ie in both the tables
Holding and Account.

I need the output like this

Select Account_Id, Branch_Cd, MarketValue from ---

But MarketValue should be calculated exactly in the above method.
How do I combine these two queries. I need it asap.
Help me out.

ThanksCheck my reply to your SUM post. If it isn't clear from that then get back to me.

Ursus|||How about:

SELECT A.Account_Id , A.Branch_Cd, B.MarketValue
FROM Accounts AS A
INNER JOIN
( SELECT SUM (dbo.HOLDING.Shares_Par_Value_Qty * dbo.ASSET.Current_Prc) AS MarketValue
FROM dbo.HOLDING
INNER JOIN dbo.ASSET
ON dbo.HOLDING.Property_Num = dbo.ASSET.Property_Num
GROUP BY dbo.HOLDING.Account_ID ) AS B
ON A.Account_ID = B.Account_ID

No comments:

Post a Comment