Help w/query pls

O

Olga

Hi,

I need to display on a monthly basis the policies sold showing the results
in a row from

their start date to the end date based on the following data:

policy_cost, date_start and date_end



Column one should display the first month (date_start) and the n column the
last month (date_end).

The difference between date_start and date_end vary from 1 month to 48.



Select Sum(Case

When Datepart(mm,date_start) = 1 then
policy_cost/Datediff(mm,date_start,date_end)) end as Jan,

..

Sum(Case

When Datepart(mm,date_start) = 12 then
policy_cost/Datediff(mm,date_start,date_end)) end as Dic

From table

Where datepart(yyyy, date_start) = 2005 **revenues with start date 2005**



The above query returns the first 12 months, how to display the rest of the
months considering

that the last policy can have date_start late December and date_end 48
months later?

Any help is highly appreciated.

Olga
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top