vendredi 26 décembre 2014

SQL Server Complex Query help needed


Before I begin, I would like to say that I know I am asking a lot but I really really can't figure out any way for the last 3 days and I've been digging like crazy. I would like to start by explaining my objective.


I have a single Database Table:



Record Id CreatedOn Division
---------- ---------- ---------
ID1001 2014-12-17 Accounting
ID1002 2014-11-10 Human Resource
ID1003 2014-12-11 Accounting


Now out of this table, I need to generate a View that has the following format



Division Dec-2013 Jan-2014 ............. Dec 2014 Total Avg Per Month
-------- --------- -------- ---------- ------ ------------
Accounting 0 0 2 34 3
Human Resource 0 0 0 32 2.9


It basically shows the number of Records per month per division, and at the end the last 2 columns shows the total per division and the average per division per month


I am trying to create a View that has the header as the first row and then the data. The reason is because I'll be using the View for a 3rd party tool that will generate the table based on the View. So if I have the columns as dynamic, the tool might fail.


I have tried everything but nothing seems to work. Please can someone help me here, maybe the way I am thinking is not the right approach.


Thanks in advance!





Aucun commentaire:

Enregistrer un commentaire