473,721 Members | 2,254 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 1674
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
2285
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
2013
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
3698
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
1815
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
3092
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
3111
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
1842
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
8065
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
2335
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
2175
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
8840
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
9367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9215
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
9131
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
4484
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4753
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3189
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
2
2576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2130
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.