473,385 Members | 2,028 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,385 software developers and data experts.

Stacked crosstab query - dynamically update columns

I have a crosstab query that compiles data for Months of the year. I
have a stacked select query on top of that crosstab query that uses
the latest 2 months data and exports it to a fixed length flat file.
Ideally I would like to be able to just select the Last 2 Columns of
the Crosstab query as inputs to the Select query WITHOUT having to go
in month after month and manually change it...

I may be asking a bit much here but is there a way to make this
happen?? I.e. this month we would be using the columns [0704] and
[0705] and next month we would use [0705] and [0706] because we would
have a new months worth of data injected into the original tables.

The only reason I want this is because these queries do a heck of a
lot of heavy lifting and they are slugs to open/modify/save so I'd
prefer to just have to export it.

Any help is greatly appreciated!

May 28 '07 #1
4 6450

"m.wanstall" <m.********@gmail.comwrote in message
news:11**********************@w5g2000hsg.googlegro ups.com...
I have a crosstab query that compiles data for Months of the year. I
have a stacked select query on top of that crosstab query that uses
the latest 2 months data and exports it to a fixed length flat file.
Ideally I would like to be able to just select the Last 2 Columns of
the Crosstab query as inputs to the Select query WITHOUT having to
go
in month after month and manually change it...

I may be asking a bit much here but is there a way to make this
happen?? I.e. this month we would be using the columns [0704] and
[0705] and next month we would use [0705] and [0706] because we
would
have a new months worth of data injected into the original tables.

The only reason I want this is because these queries do a heck of a
lot of heavy lifting and they are slugs to open/modify/save so I'd
prefer to just have to export it.

Any help is greatly appreciated!
m.wanstall,

Crosstab queries create dynamic column names based on the values of a
column in a table.

Every time such a query runs, the column names may be different.

You want to create a special query that dynamically reconfigures
itself so that it can always pick out the "correct" columns from the
ever-changing results of the crosstab.

The bad news is that there is no easy way to do that.

I can think of a way to alter your "second query" dynamically via VBA,
but it would be pointlessly complicated.

I recommend creating a VBA routine that is based on creating a
recordset using the crosstab query in question.

Using VBA, you can dynamically extract only the "last two months"
columns in the recordset and put the data into a new table you create
in the VBA code. Then run your "second query" on the new table. This
way, you never need to change your "second query".

There are various things you can do with this "intermediate" table.

You can delete it every time you run the VBA code so that it is out of
the way. You also can rename the last used "new table" by appending
the date and time (if the table actually exists) at the beginning of
your VBA code so that you keep several past copies. The second option
allows you to keep a generational history of the information you are
drawing on, so you have it later, but it also takes up more space.
Possibly Unnecessary Commentary:

I recommend examining your db schema for possible redesign of your
crosstab query, second query (with an eye to eliminating it), and
possibly the whole db. You shouldn't have to use this type of
indirection (using VBA to create intermediate quasi-temporary tables)
if your db and queries are designed correctly. That goes far beyond
the scope of your question, though.
Sincerely,

Chris O.
May 29 '07 #2
"m.wanstall" <m.********@gmail.comwrote in
news:11**********************@w5g2000hsg.googlegro ups.com:
I have a crosstab query that compiles data for Months of the
year. I have a stacked select query on top of that crosstab
query that uses the latest 2 months data and exports it to a
fixed length flat file. Ideally I would like to be able to
just select the Last 2 Columns of the Crosstab query as inputs
to the Select query WITHOUT having to go in month after month
and manually change it...

I may be asking a bit much here but is there a way to make
this happen?? I.e. this month we would be using the columns
[0704] and [0705] and next month we would use [0705] and
[0706] because we would have a new months worth of data
injected into the original tables.

The only reason I want this is because these queries do a heck
of a lot of heavy lifting and they are slugs to
open/modify/save so I'd prefer to just have to export it.

Any help is greatly appreciated!
How about taking the datediff() between date() and datefield
this will give column headers of -3,-2,-1, 0 for the last three
and the current months?

I use a set of calculated labels on a form or report to reverse
the process and show the correct period.Use the dateadd()
function.


--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

May 29 '07 #3
I'd reccomend not using a handicapped database

move to SQL Server
"Bob Quintal" <rq******@sPAmpatico.cawrote in message
news:Xn**********************@66.150.105.47...
"m.wanstall" <m.********@gmail.comwrote in
news:11**********************@w5g2000hsg.googlegro ups.com:
>I have a crosstab query that compiles data for Months of the
year. I have a stacked select query on top of that crosstab
query that uses the latest 2 months data and exports it to a
fixed length flat file. Ideally I would like to be able to
just select the Last 2 Columns of the Crosstab query as inputs
to the Select query WITHOUT having to go in month after month
and manually change it...

I may be asking a bit much here but is there a way to make
this happen?? I.e. this month we would be using the columns
[0704] and [0705] and next month we would use [0705] and
[0706] because we would have a new months worth of data
injected into the original tables.

The only reason I want this is because these queries do a heck
of a lot of heavy lifting and they are slugs to
open/modify/save so I'd prefer to just have to export it.

Any help is greatly appreciated!

How about taking the datediff() between date() and datefield
this will give column headers of -3,-2,-1, 0 for the last three
and the current months?

I use a set of calculated labels on a form or report to reverse
the process and show the correct period.Use the dateadd()
function.


--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com
Jun 25 '07 #4
"Tom Wickerqueer" <tw@ewu.eduwrote in news:OQtGdKwtHHA.488
@TK2MSFTNGP04.phx.gbl:
I'd reccomend not using a handicapped database

move to SQL Server
What has SQL server got to do with this? -Nothing.
Go away, Don;t go away mad, just go away. [plonk]

>

"Bob Quintal" <rq******@sPAmpatico.cawrote in message
news:Xn**********************@66.150.105.47...
>"m.wanstall" <m.********@gmail.comwrote in
news:11**********************@w5g2000hsg.googlegr oups.com:
>>I have a crosstab query that compiles data for Months of the
year. I have a stacked select query on top of that crosstab
query that uses the latest 2 months data and exports it to a
fixed length flat file. Ideally I would like to be able to
just select the Last 2 Columns of the Crosstab query as
inputs
>>to the Select query WITHOUT having to go in month after
month
>>and manually change it...

I may be asking a bit much here but is there a way to make
this happen?? I.e. this month we would be using the columns
[0704] and [0705] and next month we would use [0705] and
[0706] because we would have a new months worth of data
injected into the original tables.

The only reason I want this is because these queries do a
heck
>>of a lot of heavy lifting and they are slugs to
open/modify/save so I'd prefer to just have to export it.

Any help is greatly appreciated!

How about taking the datediff() between date() and datefield
this will give column headers of -3,-2,-1, 0 for the last
three
>and the current months?

I use a set of calculated labels on a form or report to
reverse
>the process and show the correct period.Use the dateadd()
function.


--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com



--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Jun 25 '07 #5

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

Similar topics

3
by: Darleen | last post by:
I am seeking conceptual here on how to get started with a "3D Matrix" in Access. We run a training center which holds multiple classes in multiple cities at multiple times. So I need to create a...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
0
by: Richard Hollenbeck | last post by:
I have a crosstab query that shows all the scores of all the activities of all the students in all courses, with the students being in the rows and the activities being in the columns and the...
2
by: deejayquai | last post by:
Hi I'm trying to produce a report based on a dynamic crosstab. Ultimately i'd like the report to actually become a sub report within a student end of year record of achievement. The dynamic...
2
by: scott.k.fraley | last post by:
....and the SELECT thats trying to pull from said Query doesn't like it one bit! ;) I'm working on this project (in Access 2002) and there is a report who's RecordSource is the following...
8
by: Penny | last post by:
(Access 2003 Multiuser Split DB, Windows XP Pro) Hi All, I would really appreciate just some basic tips on how to make a Crosstab Form based on a Crosstab Query. The query always has the same...
13
by: salad | last post by:
Operating in A97. I didn't receive much of a response conserning Pivot tables in Access. Pivot tables are nice, but a CrossTab will work for me too. Using a Pivot table, one is actually...
4
by: mattlightbourn | last post by:
Hi all, I have a problem which has been driving me nuts. Crosstab queries! I have a database witch a few different tables to do with garment manufacturing. I have a table for a client...
8
by: Paul H | last post by:
I want to base a form on a crosstab query. The query shows statistics for a user defined period. The column headings will look something like this: ClientID Month01 Month02 Month03 etc.. ...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...

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.