Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > Reporting Services
|
Reporting Services SQL Server Reporting Services. Please specify which version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Reporting Services section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 4th, 2008, 09:30 AM
Authorized User
 
Join Date: Aug 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default fill all month in matrix

Hello, I have a matrix with year and month as column headers.
I'm sure you know the problem that when I don't have data to one of the month, I have a "jump" in my matrix (from April its jump to June).

Is there a trick in RS to handle this except by changing my sql query and union it with all the month?

Thanks.

 
Old August 4th, 2008, 12:52 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Honestly, the easiest and smartest way to do this is to add a table to your DB that has one record for every year and month.

Something like this:

TABLE: allMonths
    monthYear DATETIME

and then have entries in it such as
    1/1/2008
    2/1/2008
    3/1/2008
    ...
    12/1/2008
    1/1/2009
    ..
    ...
    12/1/2029

And then you do

SELECT AM.monthYear, ...fields from other table[s]...
FROM allMonths AS AM LEFT JOIN yourTable AS T
ON ( Year(AM.monthYear) = Year(T.someDateField)
     AND Month(AM.monthYear) = Month(T.someDateField)
...

I show this in a "Calendar of Events" where I create one record per *day* in order to show all dates in a given range. Here, on my demos page:
http://www.ClearviewDesign.com/Newbie

That's for ASP code, but the principle works the same for PHP, JSP, ASP.NET, etc.
 
Old August 5th, 2008, 05:11 AM
Authorized User
 
Join Date: Aug 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
Thanks for the reply.

I was afraid that this will be the answer.

Thats the way I know but I hoped that there is a better way in RS to do that with out adding lots of waste rows.

Thank,Roy.

 
Old August 5th, 2008, 12:49 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

It's not *that* hard to do it without the extra table, but it's (a) faster, (b) simpler coding, and (c) less error prone to do it this way.

But you *could* do something like this:

<%
For yr = 2007 To 2010 ' or whatever
   Response.Write "<tr>" ' one row per year
   For mn = 1 To 12
       ' one cell per month
       Response.Write "<td>" & MonthName(mn) & " " & yr & "<br/>"
       curDate = #1/1/1900# ' dummy date, in case at EOF
       If Not RS.EOF Then curDate = RS("someDateField")
       Do While Year(curDate) = yr AND Month(curDate) = mn
           ... show data from this record ...<br/>
           RS.MoveNext ' see if another record for this same month
           If RS.EOF Then Exit Do
       Loop
       Response.Write "</td>"
   Next
   Response.Write "</tr>"
Next
%>

Something along those lines.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting month name to month number kalyanykk SQL Server 2005 7 August 19th, 2008 10:37 PM
month calendar bschleusner C# 2005 0 April 13th, 2007 09:46 PM
Sum of sub-matrix of a matrix Gromlok Java Basics 0 March 4th, 2007 03:45 PM
query Current Month, Month+1, Month+2, Month+3 anterior Access 2 September 24th, 2006 08:25 PM
Getting the current month Regornil JSP Basics 1 July 19th, 2004 09:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.