Results 1 to 3 of 3
  1. #1
    Join Date
    May 2003
    Posts
    40

    Unanswered: 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.



    Thanks

  2. #2
    Join Date
    Feb 2004
    Location
    Erehwon
    Posts
    18

    Re: Nested Query (Urgent)

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

    Ursus

  3. #3
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    How about:

    Code:
        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
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •