Getting the sum of portfolios by half years.

Posted on 2007-07-31
Last Modified: 2010-03-19
I have the following table:

PortfolioId             CUSIP                        Issue Date               CurrentAmount
---------------        -----------------            --------------------        --------------------
1                             123456XYZ                  3/2/2005                $1,000,000
1                             987654ABC                2/25/2005                $2,000,000
1                             111111XXX                7/25/2005                $3,000,000
2                             222222XXX                6/25/2006                $2,500,000  etc.

Is there a way in SQL to get the sum of each half (per portfolio).  In the example above, the sum of the first half of 2005 is $1,000,000 + $2,000,000 = $3,000,000 (for portfolio 1).  The sum of the second half for portfolio 1 is $3,000,000, etc.
Question by:techhound

    Author Comment

    Further, I need to have all the years accounted for not just one year and sorted by the half year,

    i.e., 1st Half 2005 comes before 2nd Half 2005, etc.

    LVL 4

    Accepted Solution


    Select Year(IssueDate), Ceiling(Month(IssueDate)/6), ProtfolioId,  , ,
      From Table
     Group By Year(IssueDate), Ceiling(Month(IssueDate)/6), PortfolioId

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
    Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now