Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / November 2005

Tip: Looking for answers? Try searching our database.

Query to combine 2 results

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ripon - 08 Nov 2005 02:45 GMT
Hi All:
I have a table with integer data as follows:
book  pen  bag   month cyear
10     20     30     1           2004
15     20     5        2          2005
5        5       5         2          2004
20       15   5        1          2005
--Now can I make a query to get results like:
--          feb04  feb05   jan-feb04  jan-feb05    
book    5         15         15               35
pen      5         20         25               35
bag      5         5           35               10

--Thanks in advance
Duane Hookom - 08 Nov 2005 04:15 GMT
The first step is to normalize your "I have a table". If you can't do this,
use a union query to create a normalized recordset:
SELECT Book as Qty, "Book" As Item, DateSerial(Cyear, Month, 1) as TheDate
FROM [I have a table]
UNION
SELECT Pen, "Pen", DateSerial(Cyear, Month, 1)
FROM [I have a table]
UNION
SELECT Bag, "Bag", DateSerial(Cyear, Month, 1)
FROM [I have a table];

You can then create a crosstab query with Item as the Row Heading,
Format(TheDate,"mmmyy") as the Column Heading, Sum(Qty) as the Value.

To get the jan-feb totals you can add row headings like:
JanFeb2004: Abs(Year(TheDate=2004)) * Qty
  Sum

Signature

Duane Hookom
MS Access MVP
--

> Hi All:
> I have a table with integer data as follows:
[quoted text clipped - 10 lines]
>
> --Thanks in advance
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.