473,915 Members | 5,904 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Report By Year

I have a SQL view that shows data by Category and Year - so the data may
look something like this.
Category - Year - Amount
Fruit - 2006 - $12,000
Fruit - 2007 - $16,000
Vegetables - 2006 - $15,000
Vegatables - 2007 - $25,000

Say I want to show that data in Tabular view with Category being the Y-Axis
and Year being the X-Axis, how would I go about doing this? I'm having a
hard time trying to figure out where to start. An Access-style report
doesn't seem to work because I have no way (that I know of) to have a
dynamic X-axis (years may vary based on what report the user requests). Is
the SQL query good enough or do I need to do something with the query in
order to get the years into separate columns (instead of a Year column as
above I would have a 2006 and a 2007 column containing the amounts for those
years)? A full solution may not be necessary if anyone could just point me
in the right direction to start.

Thanks for any assistance!
Ryan
Mar 20 '07 #1
8 1690
Ryan wrote:
I have a SQL view that shows data by Category and Year - so the data may
look something like this.
Category - Year - Amount
Fruit - 2006 - $12,000
Fruit - 2007 - $16,000
Vegetables - 2006 - $15,000
Vegatables - 2007 - $25,000

Say I want to show that data in Tabular view with Category being the Y-Axis
and Year being the X-Axis, how would I go about doing this?
<snip>

Yeah, this is the lacking feature in SQL Server that I miss the most
from my Access days (I'm assuming you're using SQL Server).

I don't think SQL Server will create dynamic columns for you as the
Access cross-tab did. Nevertheless, if you know the years in advance,
maybe you can use something like this (adapted straight from the
docs):

Select Category,
[2004] = Sum(Case [year] when 2004 then amount else 0 end),
[2005] = Sum(Case [year] when 2005 then amount else 0 end),
[2006] = Sum(Case [year] when 2006 then amount else 0 end),
[2007] = Sum(Case [year] when 2007 then amount else 0 end)
From YourView
Group by Category

And if you got this far, having a Totals columns is just a query away:

Select A.*, Total = (A.[2004] + A.[2005] + A.[2006] + A.[2007])
From (
Select Category,
[2004] = Sum(Case [year] when 2004 then amount else 0 end),
[2005] = Sum(Case [year] when 2005 then amount else 0 end),
[2006] = Sum(Case [year] when 2006 then amount else 0 end),
[2007] = Sum(Case [year] when 2007 then amount else 0 end)
From YourView
Group by Category
) A

HTH.

Regards,

Branco.

Mar 20 '07 #2
Thanks for the advice. Knowing the years in advance could be an issue,
because I want to allow the user to select the years they want to view (a
set of years in sequential order, ex. 2006, 2007, 2008). Though I suppose
this could still be done in SQL using a Stored Procedure with a query
similar to what you have here. I'm using a reporting tool (Component One
Reports) which is very similar to Access so I'll keep poking around on that
to see if theres an easier solution on the front-end (report) side.

Ryan

"Branco Medeiros" <br************ *@gmail.comwrot e in message
news:11******** *************@p 15g2000hsd.goog legroups.com...
Ryan wrote:
>I have a SQL view that shows data by Category and Year - so the data may
look something like this.
Category - Year - Amount
Fruit - 2006 - $12,000
Fruit - 2007 - $16,000
Vegetables - 2006 - $15,000
Vegatables - 2007 - $25,000

Say I want to show that data in Tabular view with Category being the
Y-Axis
and Year being the X-Axis, how would I go about doing this?
<snip>

Yeah, this is the lacking feature in SQL Server that I miss the most
from my Access days (I'm assuming you're using SQL Server).

I don't think SQL Server will create dynamic columns for you as the
Access cross-tab did. Nevertheless, if you know the years in advance,
maybe you can use something like this (adapted straight from the
docs):

Select Category,
[2004] = Sum(Case [year] when 2004 then amount else 0 end),
[2005] = Sum(Case [year] when 2005 then amount else 0 end),
[2006] = Sum(Case [year] when 2006 then amount else 0 end),
[2007] = Sum(Case [year] when 2007 then amount else 0 end)
From YourView
Group by Category

And if you got this far, having a Totals columns is just a query away:

Select A.*, Total = (A.[2004] + A.[2005] + A.[2006] + A.[2007])
From (
Select Category,
[2004] = Sum(Case [year] when 2004 then amount else 0 end),
[2005] = Sum(Case [year] when 2005 then amount else 0 end),
[2006] = Sum(Case [year] when 2006 then amount else 0 end),
[2007] = Sum(Case [year] when 2007 then amount else 0 end)
From YourView
Group by Category
) A

HTH.

Regards,

Branco.

Mar 20 '07 #3
Post your question to microosft.publi c.sqlserver.pro gramming. I believe you
*can* do this with a SQLServer query, and they would be the ones to tell
you how.

Then come back and post the answer here so we know, too. ;-)

Robin S.
------------------------------------------------------
"Ryan" <Ty****@newsgro ups.nospamwrote in message
news:ug******** ******@TK2MSFTN GP05.phx.gbl...
Thanks for the advice. Knowing the years in advance could be an issue,
because I want to allow the user to select the years they want to view (a
set of years in sequential order, ex. 2006, 2007, 2008). Though I
suppose this could still be done in SQL using a Stored Procedure with a
query similar to what you have here. I'm using a reporting tool
(Component One Reports) which is very similar to Access so I'll keep
poking around on that to see if theres an easier solution on the
front-end (report) side.

Ryan

"Branco Medeiros" <br************ *@gmail.comwrot e in message
news:11******** *************@p 15g2000hsd.goog legroups.com...
>Ryan wrote:
>>I have a SQL view that shows data by Category and Year - so the data
may
look something like this.
Category - Year - Amount
Fruit - 2006 - $12,000
Fruit - 2007 - $16,000
Vegetables - 2006 - $15,000
Vegatables - 2007 - $25,000

Say I want to show that data in Tabular view with Category being the
Y-Axis
and Year being the X-Axis, how would I go about doing this?
<snip>

Yeah, this is the lacking feature in SQL Server that I miss the most
from my Access days (I'm assuming you're using SQL Server).

I don't think SQL Server will create dynamic columns for you as the
Access cross-tab did. Nevertheless, if you know the years in advance,
maybe you can use something like this (adapted straight from the
docs):

Select Category,
[2004] = Sum(Case [year] when 2004 then amount else 0 end),
[2005] = Sum(Case [year] when 2005 then amount else 0 end),
[2006] = Sum(Case [year] when 2006 then amount else 0 end),
[2007] = Sum(Case [year] when 2007 then amount else 0 end)
From YourView
Group by Category

And if you got this far, having a Totals columns is just a query away:

Select A.*, Total = (A.[2004] + A.[2005] + A.[2006] + A.[2007])
From (
Select Category,
[2004] = Sum(Case [year] when 2004 then amount else 0 end),
[2005] = Sum(Case [year] when 2005 then amount else 0 end),
[2006] = Sum(Case [year] when 2006 then amount else 0 end),
[2007] = Sum(Case [year] when 2007 then amount else 0 end)
From YourView
Group by Category
) A

HTH.

Regards,

Branco.


Mar 20 '07 #4
Hi Ryan,

For the report you want to present, I think the SQL Server reporting
service is quite good for present such summary data. And the Matrix data
region in Reporting Service is the exact one that can present the data view
you want. You can have a look at the following reference:

#SQL Server 2005 Books Online Working with Matrix Data Regions
http://msdn2.microsoft.com/en-us/library/ms157334.aspx

#Reporting Services - Getting the Matrix to Display Two Subtotals for the
Same Group
http://www.sqlskills.com/blogs/liz/2...sGettingTheMat
rixToDisplayTwo SubtotalsForThe SameGroup.aspx

Also, if you do not want to install reporting service, and only want to
present such a report in your client application, Visual Studio 2005 has
provided a reportviewer control(for both ASP.NET and winform application)
that can display client report(use the same template syntax as Sql server
reporting service report). Here are some useful articles discussing on
using ReportViewer control of VisualStudio 2005:

#Adding Data Regions to a ReportViewer Report
http://msdn2.microsoft.com/en-us/lib...86(VS.80).aspx

#Adding Matrix Data Regions
http://msdn2.microsoft.com/en-us/lib...09(VS.80).aspx

#Build Client-Side Reports Easily
http://www.ftponline.com/vsm/2005_11...res/rjennings/

#ReportViewer Control in Visual Studio 2005
http://gotreportviewer.com/

Hope this helps. If you have any more specific questions on this, please
feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

=============== =============== =============== =====

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.
Mar 21 '07 #5
Steven,

Thanks this is just what I needed. I'm able to create the matrix to get the
data I want. The downsides so far is that I am having trouble getting the
column headers for my static fields to show up, the matrix fields that have
no data need to show 0 but they're showing up as blanks, and I'm not real
fond of the report designer interface. But I guess those are all things
I'll get used to and/or find a fix for eventually.

Ryan

"Steven Cheng[MSFT]" <st*****@online .microsoft.comw rote in message
news:Nk******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Hi Ryan,

For the report you want to present, I think the SQL Server reporting
service is quite good for present such summary data. And the Matrix data
region in Reporting Service is the exact one that can present the data
view
you want. You can have a look at the following reference:

#SQL Server 2005 Books Online Working with Matrix Data Regions
http://msdn2.microsoft.com/en-us/library/ms157334.aspx

#Reporting Services - Getting the Matrix to Display Two Subtotals for the
Same Group
http://www.sqlskills.com/blogs/liz/2...sGettingTheMat
rixToDisplayTwo SubtotalsForThe SameGroup.aspx

Also, if you do not want to install reporting service, and only want to
present such a report in your client application, Visual Studio 2005 has
provided a reportviewer control(for both ASP.NET and winform application)
that can display client report(use the same template syntax as Sql server
reporting service report). Here are some useful articles discussing on
using ReportViewer control of VisualStudio 2005:

#Adding Data Regions to a ReportViewer Report
http://msdn2.microsoft.com/en-us/lib...86(VS.80).aspx

#Adding Matrix Data Regions
http://msdn2.microsoft.com/en-us/lib...09(VS.80).aspx

#Build Client-Side Reports Easily
http://www.ftponline.com/vsm/2005_11...res/rjennings/

#ReportViewer Control in Visual Studio 2005
http://gotreportviewer.com/

Hope this helps. If you have any more specific questions on this, please
feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

=============== =============== =============== =====

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no
rights.


Mar 21 '07 #6
Thanks for your reply Ryan,

For column header of static columns, I've ever found some existing
discussion on this and static columns seems hasn't header text setting as
dynamic column. However, someone has been able to use the top/left cell to
add some header text for all those static columns.

In addition, here are some other useful resource on reportviewer based
client report designing:

#Walkthrough: Creating a ReportViewer Report
http://msdn2.microsoft.com/en-us/lib...73(VS.80).aspx

#Defining a Report Layout
http://msdn2.microsoft.com/en-us/lib...86(VS.80).aspx

#ReportViewer User Interface Reference
http://msdn2.microsoft.com/en-us/lib...80(VS.80).aspx

http://blogs.msdn.com/ChrisHays/

Hope this also helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.




Mar 22 '07 #7
Hi Steven,

Thats exactly the workaround I ended up using, I put a table in the upper
left cell of the matrix that had static header names. Thanks for the links!

Ryan
"Steven Cheng[MSFT]" <st*****@online .microsoft.comw rote in message
news:7C******** *****@TK2MSFTNG HUB02.phx.gbl.. .
Thanks for your reply Ryan,

For column header of static columns, I've ever found some existing
discussion on this and static columns seems hasn't header text setting as
dynamic column. However, someone has been able to use the top/left cell to
add some header text for all those static columns.

In addition, here are some other useful resource on reportviewer based
client report designing:

#Walkthrough: Creating a ReportViewer Report
http://msdn2.microsoft.com/en-us/lib...73(VS.80).aspx

#Defining a Report Layout
http://msdn2.microsoft.com/en-us/lib...86(VS.80).aspx

#ReportViewer User Interface Reference
http://msdn2.microsoft.com/en-us/lib...80(VS.80).aspx

http://blogs.msdn.com/ChrisHays/

Hope this also helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.




Mar 22 '07 #8
You're welcome :)

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

Mar 23 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2289
by: AstrA | last post by:
Hi All Wondered if you could help. Basically I have 2 tables that contain all the data I want for my report, but I need to put it in a particular way and I need to display it in an ASP page so my queries got to be manual rather than an MS Excel/Query 'munge'. To be honest, the report itself is very basic, so hopefully my ramble will make sense. I need to report that shows 6 columns at best, 4 columns if
1
2024
by: Rajani | last post by:
Hello, I have a table(msaccess) with the structure... job_code text 6 style text 10 qty number fabrication text 65 ship_date date/time
5
3703
by: Tony Williams | last post by:
I have a table "tblmaintabs" that stores data that is collected from various companies on a quarterly basis in March, June, September and December each year (these dates are stored in a Date/time field called txtmonthlabel formatted mmmm yyyy). I am trying to create a report that shows the figures for the same quarter last year and the figures for the year to date this year and last year. The value is shown on the report in the control...
0
1826
by: Rahul Chatterjee | last post by:
Hello All I have designed a dotnet application using VB which basically takes a selection and passes value to a crystal report which in turn passes the value to a Stored procedure. After the report gets generated it is PDF'ed - all this is done thru a single click in my program. Now the catch here is that through the program all these tasks of generating the report and PDF'ing 1400 records (about 25 pages) takes 15 minutes.
2
3105
by: john | last post by:
My report is based on a query with user input . In my report I have a text box with the following code: =. This works when the query outcome is 1 or more records. But when the query output is zero records this field shows #Error while I would like this text box to still show the year the user entered. The user input doesn't seem to be available when there is no query outcome. Anyone an idea to make this possible? thanks, john
12
3123
by: kabradley | last post by:
Hello, Thanks for looking at my post and hopefully having an answer or at least a suggestion to my problem. I currently work at a financial planning office that deals with many clients and accounts. Each client may have multiple accounts such as an individual, IRA, and possibly a joint tenant account. Each one of these accounts for the particular client is contained in a 'Portfolio'. For example, Joe Smith may have 3 accounts: Joe Smith...
6
1848
by: DavidOwens | last post by:
Sub PreviewReport_Click() On Error GoTo Err_PreviewReport_Click Dim stRepName As String: Rem Holds the Report name Dim stDispId As String: Rem Holds the Dispenser ID Dim stQuery As String: Rem Holds the Query name Dim stWhere As String: Rem Holds the where clause Dim stExtra As String: Dim stMonthYear, stYear, stWeekCount As String Dim intX As Integer, rst As Recordset
69
8115
by: kabradley | last post by:
Alrighty Guys and Gals, I have another question that I hope you all can help me with. I have a report that uses a cross-tab query as its record source. This cross-tab query is getting all of its information from another query. That query, qryRpt, is pulling information from several different tables. One of these table is tblDistributions, a table that holds monthly distributions for a particular investment, and the second is tblDeduction, a...
5
2348
by: LadyIlsebet | last post by:
I'm not a fantastic Access developer, but I'm trying to help get Inventory and whatnot organized at work. They are used to 5 year budget plans that list out exactly what has to be purchased what year and how much it will cost. Currently these are kept in Excel and look like this | Inventory information (who, what, where) | 2008 | 2009 | 2010 | 2011| 2012 The cost for the item is displayed in the column in the year when it
9
2186
by: magickarle | last post by:
Hi, I have a database in access with the following columns: Day AgentID ManagerID Grade They got information about agents and some grades. I would like to have ONE form with several grouping (yearly quarterly and weekly) with the respective average.
0
10039
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9883
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10928
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9734
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8102
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7259
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4779
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.