SQL column to list months
Posted on 2014-08-11
The SQL report I'm building requires the following two columns:
1. Period: List the month and year (MM/YYYY) for all the months included within date range specified.
2. Loans: Number of loans with a create date during the associated period
User selects Date Range 1/1/2014 to 3/31/2014, and runs the report. Data returned should be:
Period Loans ........ More columns based on date range
What would be the best way to list the months as rows/records returned? I'm thinking Union, but was really hoping an expert could suggest an easier or more efficient way.
Note: Performance is top priority, as the DB contains millions of records.