A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Single Query



 
 
Thread Tools Display Modes
  #1  
Old July 8th, 2009, 07:36 AM posted to microsoft.public.access.queries
Ananth
external usenet poster
 
Posts: 81
Default Single Query

I have 3 year Spend data pulled from the Hyperion in the following format

Supplier_ID
Site_ID
Year
Jan $
Feb $
Mar $
Apr $
May $
Jun $
Jul $
Aug $
Sep $
Nov $
Dec $

Is it possible using a single query to restate the above database to the
following format

Supplier_ID
Site_ID
Year
Spend $
Month Ref


Ananth
  #2  
Old July 8th, 2009, 12:15 PM posted to microsoft.public.access.queries
vanderghast
external usenet poster
 
Posts: 593
Default Single Query

Sure, in SQL view:


SELECT supplier_ID, site_ID, DateSerial(Year, 1, 1) AS FirstOfMonth, [Jan $]
AS [Spend $] FROM table
UNION ALL
SELECT supplier_ID, site_ID, DateSerial(Year, 2, 1), [Feb $] FROM table
UNION ALL
SELECT supplier_ID, site_ID, DateSerial(Year, 3, 1), [Mar $] FROM table
UNION ALL
SELECT supplier_ID, site_ID, DateSerial(Year, 4, 1), [Apr $] FROM table
.....
UNION ALL
SELECT supplier_ID, site_ID, DateSerial(Year, 12, 1), [Dec $] FROM table




Note that I combined year and month into a single date, the first of the
month of the year.


Vanderghast, Access MVP


"Ananth" wrote in message
...
I have 3 year Spend data pulled from the Hyperion in the following format

Supplier_ID
Site_ID
Year
Jan $
Feb $
Mar $
Apr $
May $
Jun $
Jul $
Aug $
Sep $
Nov $
Dec $

Is it possible using a single query to restate the above database to the
following format

Supplier_ID
Site_ID
Year
Spend $
Month Ref


Ananth


  #3  
Old July 8th, 2009, 12:16 PM posted to microsoft.public.access.queries
vanderghast
external usenet poster
 
Posts: 593
Default Single Query

Sure, in SQL view:


SELECT supplier_ID, site_ID, DateSerial(Year, 1, 1) AS FirstOfMonth, [Jan $]
AS [Spend $] FROM table
UNION ALL
SELECT supplier_ID, site_ID, DateSerial(Year, 2, 1), [Feb $] FROM table
UNION ALL
SELECT supplier_ID, site_ID, DateSerial(Year, 3, 1), [Mar $] FROM table
UNION ALL
SELECT supplier_ID, site_ID, DateSerial(Year, 4, 1), [Apr $] FROM table
.....
UNION ALL
SELECT supplier_ID, site_ID, DateSerial(Year, 12, 1), [Dec $] FROM table




Note that I combined year and month into a single date, the first of the
month of the year.


Vanderghast, Access MVP


"Ananth" wrote in message
...
I have 3 year Spend data pulled from the Hyperion in the following format

Supplier_ID
Site_ID
Year
Jan $
Feb $
Mar $
Apr $
May $
Jun $
Jul $
Aug $
Sep $
Nov $
Dec $

Is it possible using a single query to restate the above database to the
following format

Supplier_ID
Site_ID
Year
Spend $
Month Ref


Ananth


  #4  
Old July 8th, 2009, 12:24 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 2,364
Default Single Query

You would need to use a UNION query with twelve query clauses.

SELECT Supplier_ID, Site_ID, [Year], [Jan $] as [Spend $]
, "Jan" as [Month Ref]
FROM [YourCurrentTable]
UNION ALL
SELECT Supplier_ID, Site_ID, [Year], [Feb $] as [Spend $]
, "Feb" as [Month Ref]
FROM [YourCurrentTable]
UNION ALL
SELECT Supplier_ID, Site_ID, [Year], [Mar $] as [Spend $]
, "Mar" as [Month Ref]
FROM [YourCurrentTable]
UNION ALL
....

By the way good field names would not include the $ or spaces. And Year
is a reserved word in Access. I would use names like DollarsSpent,
MonthRef, and YearRef.


'================================================= ===
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'================================================= ===


Ananth wrote:
I have 3 year Spend data pulled from the Hyperion in the following format

Supplier_ID
Site_ID
Year
Jan $
Feb $
Mar $
Apr $
May $
Jun $
Jul $
Aug $
Sep $
Nov $
Dec $

Is it possible using a single query to restate the above database to the
following format

Supplier_ID
Site_ID
Year
Spend $
Month Ref


Ananth

  #5  
Old July 8th, 2009, 12:35 PM posted to microsoft.public.access.queries
vanderghast
external usenet poster
 
Posts: 593
Default Single Query

Sure, in SQL view:


SELECT supplier_ID, site_ID, DateSerial(Year, 1, 1) AS FirstOfMonth, [Jan $]
AS [Spend $] FROM table
UNION ALL
SELECT supplier_ID, site_ID, DateSerial(Year, 2, 1), [Feb $] FROM table
UNION ALL
SELECT supplier_ID, site_ID, DateSerial(Year, 3, 1), [Mar $] FROM table
UNION ALL
SELECT supplier_ID, site_ID, DateSerial(Year, 4, 1), [Apr $] FROM table
.....
UNION ALL
SELECT supplier_ID, site_ID, DateSerial(Year, 12, 1), [Dec $] FROM table




Note that I combined year and month into a single date, the first of the
month of the year.


Vanderghast, Access MVP


"Ananth" wrote in message
...
I have 3 year Spend data pulled from the Hyperion in the following format

Supplier_ID
Site_ID
Year
Jan $
Feb $
Mar $
Apr $
May $
Jun $
Jul $
Aug $
Sep $
Nov $
Dec $

Is it possible using a single query to restate the above database to the
following format

Supplier_ID
Site_ID
Year
Spend $
Month Ref


Ananth


  #6  
Old July 8th, 2009, 12:35 PM posted to microsoft.public.access.queries
vanderghast
external usenet poster
 
Posts: 593
Default Single Query

Sure, in SQL view:


SELECT supplier_ID, site_ID, DateSerial(Year, 1, 1) AS FirstOfMonth, [Jan $]
AS [Spend $] FROM table
UNION ALL
SELECT supplier_ID, site_ID, DateSerial(Year, 2, 1), [Feb $] FROM table
UNION ALL
SELECT supplier_ID, site_ID, DateSerial(Year, 3, 1), [Mar $] FROM table
UNION ALL
SELECT supplier_ID, site_ID, DateSerial(Year, 4, 1), [Apr $] FROM table
.....
UNION ALL
SELECT supplier_ID, site_ID, DateSerial(Year, 12, 1), [Dec $] FROM table




Note that I combined year and month into a single date, the first of the
month of the year.


Vanderghast, Access MVP


"Ananth" wrote in message
...
I have 3 year Spend data pulled from the Hyperion in the following format

Supplier_ID
Site_ID
Year
Jan $
Feb $
Mar $
Apr $
May $
Jun $
Jul $
Aug $
Sep $
Nov $
Dec $

Is it possible using a single query to restate the above database to the
following format

Supplier_ID
Site_ID
Year
Spend $
Month Ref


Ananth


  #7  
Old July 9th, 2009, 06:06 AM posted to microsoft.public.access.queries
Ananth
external usenet poster
 
Posts: 81
Default Single Query

John

Thanks for yr suggestion. I have taken note of yr advise too re data names.

Ananth

"John Spencer" wrote:

You would need to use a UNION query with twelve query clauses.

SELECT Supplier_ID, Site_ID, [Year], [Jan $] as [Spend $]
, "Jan" as [Month Ref]
FROM [YourCurrentTable]
UNION ALL
SELECT Supplier_ID, Site_ID, [Year], [Feb $] as [Spend $]
, "Feb" as [Month Ref]
FROM [YourCurrentTable]
UNION ALL
SELECT Supplier_ID, Site_ID, [Year], [Mar $] as [Spend $]
, "Mar" as [Month Ref]
FROM [YourCurrentTable]
UNION ALL
....

By the way good field names would not include the $ or spaces. And Year
is a reserved word in Access. I would use names like DollarsSpent,
MonthRef, and YearRef.


'================================================= ===
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'================================================= ===


Ananth wrote:
I have 3 year Spend data pulled from the Hyperion in the following format

Supplier_ID
Site_ID
Year
Jan $
Feb $
Mar $
Apr $
May $
Jun $
Jul $
Aug $
Sep $
Nov $
Dec $

Is it possible using a single query to restate the above database to the
following format

Supplier_ID
Site_ID
Year
Spend $
Month Ref


Ananth


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:02 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.