473,382 Members | 1,376 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Simple but complex report

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
it's easier. Report looks like the following:

Account Code - standard text field
Account Name - standard text field

Turnover (Year to Date) 2002 - standard decimal number (single??) field
Turnover (Year to Date) 2003 - standard decimal number (single??) field

(not vital, but would be nice)
Deviation as a straight figure between what the 2003 turnover figure is
against the 2002 figure - ad hoc calc field
Deviation as a % between what the 2003 turnover figure is against the 2002
figure - ad hoc calc field

My table structure is as follows:

TABLE 1 - ACCOUNTS

This contains all of the account codes (PK) and names as ACCOUNTID and NAME
respectively. It also contains a field called LEDGER which I would need to
use in a Where clause to set this to 1 (1 = sales and 2 = purchases).

TABLE 2 - ACCOUNTBUDGETS

This contains the Turnover details and is linked to the ACCOUNTS table by an
ACCOUNTID (FK??). This table contains a TURNOVER field for the actual
turnover amount, a PERIOD field for the months of a year (eg, 1 - 12 - that
being Jan to Dec) and a YEAR field for the relevant years.

In this ACCOUNTBUDGETS table it basically keeps a line-by-line record of
each turnover for each period and year for each account code. As you
probably would with any transaction line storing table.

An important part of this is that I want to show all of the Account codes
and names that relate to LEDGER=1 even if they have no entries in the
ACCOUNTSBUDGETS table. The reason being is that I want to be able to show
that an account might not have traded for 2002 and therefore their 2003 Year
to date might be really good cos they've sold loads in 2003.

So the final part is that I need summarise the Year to date figures next to
each account code and name. To do this I need to take what the month number
is now (eg, Dec = 12) and summarise all the turnover figures for 2002 upto
12 and then all the turnover figures for 2003 upto 12. If you can imagine
when this report is run in March the report would summarize from 1 to 3
rather than 1 - 12 in the last examples.

The nice bits on the end would be that they would give 2 different calcs
against what the 2 turnover figures stated.

The result should be something like the following:

December Turnover YTD
Deviation
Acc No: Account Name 2003 2002 £
%
A001 Alpha Motor 9,250 5,398 3,852
71%
A003 A J V Secure 0
94 -1,294 -100%
A004 Aye Gee 0
39 -4,239 -100%
A007 P H Allin 2,235
08 -1,973 -47%

Any ideas??

Rgds

Robbie

Jul 20 '05 #1
3 2269
AstrA (no*****@noemail.com) writes:
TABLE 1 - ACCOUNTS

This contains all of the account codes (PK) and names as ACCOUNTID and
NAME respectively. It also contains a field called LEDGER which I would
need to use in a Where clause to set this to 1 (1 = sales and 2 =
purchases).

TABLE 2 - ACCOUNTBUDGETS

This contains the Turnover details and is linked to the ACCOUNTS table
by an ACCOUNTID (FK??). This table contains a TURNOVER field for the
actual turnover amount, a PERIOD field for the months of a year (eg, 1 -
12 - that being Jan to Dec) and a YEAR field for the relevant years.

This is a complete guessing game, but this may get you started:

SELECT a.accountid, a.name, a.ledger,
turnover = colaesce(ab.turnover, 0), ab.stdev
FRON accounts a
LEFT JOIN (SELECT accountid, turnover = SUM(turnover),
stdev = STDEV(turnover)
FROM accountbudgets ab
GROUP BY accountid, year) ON a.accoundid = b.accountid

If you desire further assistance, here are the standard recommendation
for this kind of inquiries:

o Include CREATE TABLE definitions for your tables.
o Include INSERT statements with sample data.
o Include the desired output from that data.
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2
Hi Erland

Thanks for getting back to me. The breakdown is as follows:

TABLE 1 - ACCOUNTS

CREATE TABLE [dbo].[ACCOUNTS] (
[ACCOUNTID] [T_ACCOUNTSDOMAIN] NOT NULL ,
[NAME] [varchar] (40) NOT NULL ,
[COMMENT] [varchar] (255) NULL ,
[PEOPLEID] [T_PEOPLEDOMAIN] NULL ,
[LEDGER] [smallint] NULL ,
[Status] [smallint] NOT NULL ,
[CURRENCYID] [T_CURRENCIESDOMAIN] NULL ,
[FIXEDVATRATE] [tinyint] NOT NULL ,
[VATRATEID] [T_VATRATESDOMAIN] NULL ,
[OURACCOUNTID] [varchar] (40) NULL ,
[AGENTID] [T_AGENTSDOMAIN] NULL ,
[SALESCENTREID] [T_SALESCENTRESDOMAIN] NULL ,
[COSTCENTREID] [T_COSTCENTRESDOMAIN] NULL ,
[DEPARTMENTID] [T_DEPARTMENTSDOMAIN] NULL ,
[WAREHOUSEID] [T_WAREHOUSESDOMAIN] NULL ,
[DELETETRANSACTIONS] [tinyint] NOT NULL ,
[BALANCE] [money] NOT NULL ,
[TURNOVER] [money] NOT NULL ,
[CREDITLIMIT] [money] NOT NULL ,
[REMITTANCECONTACTID] [T_CONTACTDETAILSDOMAIN] NULL ,
[STATEMENTCONTACTID] [T_CONTACTDETAILSDOMAIN] NULL ,
[InvoiceContactID] [T_CONTACTDETAILSDOMAIN] NULL ,
[DeliveryContactID] [T_CONTACTDETAILSDOMAIN] NULL ,
[OrdersContactID] [T_CONTACTDETAILSDOMAIN] NULL ,
[TRADINGTERMS] [varchar] (100) NULL ,
[SETTLEMENTPERCENT] [float] NULL ,
[TRADINGTYPE] [smallint] NULL ,
[TRADINGDAYOFMONTH] [smallint] NULL ,
[TRADINGDAYSTIME] [smallint] NULL ,
[USETRADINGTERMS] [tinyint] NOT NULL ,
[PRICELEVELID] [T_PRICELEVELSDOMAIN] NULL ,
[DISCOUNTPERCENT] [float] NULL ,
[LASTINVOICEDATE] [datetime] NULL ,
[LASTPAYMENTDATE] [datetime] NULL ,
[PRINTSTATEMENTS] [tinyint] NOT NULL ,
[PRINTRUNNINGBALANCES] [tinyint] NOT NULL ,
[BANKNAME] [varchar] (40) NULL ,
[BANKADDRESSLINE1] [varchar] (40) NULL ,
[BANKADDRESSLINE2] [varchar] (40) NULL ,
[BANKADDRESSLINE3] [varchar] (40) NULL ,
[BANKTOWN] [varchar] (40) NULL ,
[BANKCOUNTY] [varchar] (40) NULL ,
[BANKCOUNTRY] [varchar] (40) NULL ,
[BANKPOSTCODE] [varchar] (40) NULL ,
[BANKTITLE] [varchar] (40) NULL ,
[BANKFIRSTNAME] [varchar] (40) NULL ,
[BANKSURNAME] [varchar] (40) NULL ,
[BANKPOSITION] [varchar] (40) NULL ,
[BANKTELEPHONE] [varchar] (40) NULL ,
[BANKTELEX] [varchar] (40) NULL ,
[BANKFAX] [varchar] (40) NULL ,
[BANKEMAIL] [varchar] (40) NULL ,
[BANKSORTCODE] [varchar] (40) NULL ,
[BANKACCOUNTID] [varchar] (40) NULL ,
[BANKACCOUNTNAME] [varchar] (40) NULL ,
[BANKACCOUNTSWIFT] [varchar] (40) NULL ,
[SPOOLLOCK] [tinyint] NOT NULL ,
[TIMESTAMP] [timestamp] NOT NULL
)
GO

Sample data from this is as follows:

accountid name
---------------------------------------- -----------------------------------
-----
G01 German Customer
NL01 Netherlands Customer
UK01 UK Customer

I only want the Account ID and Name from this table where the Ledger = 1
TABLE 2 - ACCOUNTSBUDGET

CREATE TABLE [dbo].[ACCOUNTSBUDGET] (
[ACCOUNTID] [T_ACCOUNTSDOMAIN] NOT NULL ,
[DEPARTMENTID] [T_DEPARTMENTSDOMAIN] NOT NULL ,
[YEAR] [smallint] NOT NULL ,
[PERIOD] [smallint] NOT NULL ,
[TURNOVER] [money] NOT NULL ,
[TURNOVERBUDGET] [money] NOT NULL ,
[PAYMENTS] [money] NOT NULL ,
[PAYMENTSBUDGET] [money] NOT NULL ,
[PROFIT] [money] NOT NULL ,
[PROFITBUDGET] [money] NOT NULL ,
[TIMESTAMP] [timestamp] NOT NULL
)
GO

Sample data from this is as follows:

accountid year period turnover
---------------------------------------- ------ ------ ---------------------
UK01 2003 3 200.0000
UK01 2003 6 300.0000
UK01 2003 12 500.0000

I want the total sumation from period 1 to whatever the current month is (eg
it is 12 at the moment) for last year (ie, currently 2002) and this year
(ie, currently 2003) for each account in the ACCOUNTS table. The reason for
this is that there might not be entries for certain accounts in the
ACCOUNTSBUDGET table, as it is a sort of line-by-line storer when a
transaction is placed for a particular period (ie, month) and year.
RESULTS

The results I want are as follows:

December Turnover YTD Deviation
Acc No: Account Name 2003 2002 £ %
A001 Alpha Motor 9,250 5,398 3,852 71%
etc etc etc etc etc
etc
I hope this defines it better, but please ask me if you need anymore.

Rgds

Robbie
Erland Sommarskog <so****@algonet.se> wrote in message
news:Xn*********************@127.0.0.1...
AstrA (no*****@noemail.com) writes:
TABLE 1 - ACCOUNTS

This contains all of the account codes (PK) and names as ACCOUNTID and
NAME respectively. It also contains a field called LEDGER which I would
need to use in a Where clause to set this to 1 (1 = sales and 2 =
purchases).

TABLE 2 - ACCOUNTBUDGETS

This contains the Turnover details and is linked to the ACCOUNTS table
by an ACCOUNTID (FK??). This table contains a TURNOVER field for the
actual turnover amount, a PERIOD field for the months of a year (eg, 1 -
12 - that being Jan to Dec) and a YEAR field for the relevant years.

This is a complete guessing game, but this may get you started:

SELECT a.accountid, a.name, a.ledger,
turnover = colaesce(ab.turnover, 0), ab.stdev
FRON accounts a
LEFT JOIN (SELECT accountid, turnover = SUM(turnover),
stdev = STDEV(turnover)
FROM accountbudgets ab
GROUP BY accountid, year) ON a.accoundid = b.accountid

If you desire further assistance, here are the standard recommendation
for this kind of inquiries:

o Include CREATE TABLE definitions for your tables.
o Include INSERT statements with sample data.
o Include the desired output from that data.
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3
Laphan (ne**@DoNotEmailMe.co.uk) writes:
Thanks for getting back to me. The breakdown is as follows:


Thanks for tables and the sample data, but:

1) The table definitions refers to user-defined types that are
not installed.
2) The sample data is not in form of INSERT statements.
3) You mention a requirement of a ledger 1, but there is no appearance
of any ledger at all in the sample data, nor the output, so I can't
verify that I am using it correctly.
4) The sample output does not match with with the sample data. The
fact that the names and ids are different are one thing, but the
sample data only has data for 2003, so I can't see where the data
for 2002 comes in. And I cannot really make any connection from
the values in the sample data to the values in the sample output.

Also, the sample output is difficult to read. I don't know if you
composed the message with a proportional font, of you if you used
tab characters that were mangled. The tables for the sample input
were OK with regards to format. (But they should have been INSERT
statements.)

It's not that I want to slam you, but you are the one who is having a
problem and want help, so it seems fair if you on your part to do
the dirty work. And while correct sample data with coherent input
and output may take some to compose, this is is data that you will
have use for in future tests of your development.
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #4

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

Similar topics

0
by: mjcsfo | last post by:
I can't seem to find a reference nor any helpful threads on this topic. I've gotten the following error in two circumstances: 1. A complex type has nested within it another complex type, in the...
1
by: Volker Zink | last post by:
I am writing my first schema and have 3 complex types which represent "top level objects": <complex type name="A1"> .... </complex type> <complex type name="A2"> .... </complex type>
5
by: HQM | last post by:
If I create an element X of a primitive type with minOccurs=0 and nillable=true and run it through the WSDL generator I get a class with a property "X" of the primitive type plus a boolean...
3
by: Don Sealer | last post by:
I'm guessing this is pretty simple however not simple enough for me. I'm developing a database to track expenses, income, banking transactions, etc. I have a very simple query with four fields,...
7
by: abcd | last post by:
I am trying to set up client machine and investigatging which .net components are missing to run aspx page. I have a simple aspx page which just has "hello world" printed.... When I request...
14
by: robert | last post by:
For testing purposes I'm looking for a simple DAV server - best a python thing serving a folder tree. Don't want to install/change/setup the complex apache dav .. Found PyDav...
2
by: DeanL | last post by:
Hi everyone, I'm trying to produce a report in Access 97 that shows the difference between 2 sets of 2 fields (Estimated Cost against Actual Cost and then Estimated Working Days against Actual...
15
by: Bjoern Schliessmann | last post by:
Hello all, I'm trying to simulate simple electric logic (asynchronous) circuits. By "simple" I mean that I only want to know if I have "current" or "no current" (it's quite digital) and the only...
1
by: Randy Volkart | last post by:
I'm trying to fix a glitch in a complex access database, and have a fairly complex problem... unless there's some obscure easy fix I don't know being fairly new with Access. Basically, the area...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.