Solved

Getting the sum of portfolios by half years.

Posted on 2007-07-31
133 Views
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.
0
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.

Thanks
0

LVL 4

Accepted Solution

try

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

Featured Post

Suggested Solutions

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…
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…