473,387 Members | 1,693 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,387 software developers and data experts.

Querying Column Names/ Running Week totals

Boxcar74
Ok I don’t know if this is possible. I Know SQL Ok and it’s been a while since I worked with VB.

But what I’m trying to do is query by the dates in the column names.

For instance I'm tracking different kinds of issues (Example A, B, C)
on 4/26 I start with a query starting 4/21 – 4/25 to get the last 5 days of data, that is simple; I just use the design view and select the columns heading.

Issue 4/21 4/22 4/23 4/24 4/25 4/26 4/27 4/28 4/29
A 1 0 3 0 4 0 1 2 0
B 2 8 6 6 2 1 0 8 1
C 0 2 4 4 4 6 2 3 0


But what I need to do is create a query that AWAYS (everyday) get the last 5 days of DATA without manually updating the query every day.

Any help will be appreciated!!

BTW
In Reality I need the last three queries for the last 13 days, 13 weeks and 13 months data eveyday/week/month and I’m dealing with a DB that has columns going back years and on average 6000 + records.
May 7 '07 #1
14 2029
Rabbit
12,516 Expert Mod 8TB
So... you're talking a dynamic crosstab query?

You can use two queries, one to return records on the past 5 days, also returning the date. And the second would be the crosstab. Although note that this isn't very practical for a report because the field names would be changing constantly.
May 7 '07 #2
I don't think that would work. THe query results are link to a spreadsheets, so it would get all messed up with that. and in the end I will have too many of them

Is there a way to just pick X amounts of coulmns? From a given date? Or Cloumns 5,4,3,2,1. Iv'e tried many differant ways with no luck.
May 7 '07 #3
Rabbit
12,516 Expert Mod 8TB
I'm not quite sure I understand, is that sample data not the result of a crosstab query?
May 7 '07 #4
No unfortunately the columns heading on the table have Dates in them I have two other tables with weeks and months as the columns names.

The rows I have various issues I’m tracking by category and each row shows the number of times the issue occurred during those dates. (One of the reasons I don’t think I can use a cross tab query is that I am tracking 4 columns of categories)

I'll try to explain with a better example:
Example Column headings (a more real example than I used before)
Category, Subcategory, Issue, Issue type, 4/17, 4/18, 4/19 etc...

Example row would be:
Hardware, hard drive, booting, not booting, 1, 3 2 etc….

(1,3,2 are the number of time this issue occured on that date in the cloumn name)

The dates go in indefinitely and I need to query the last 13 weeks.

I'm not sure wich direction to go with this.

I hope this clarifies it for you.

Rabbit thank you very much. You Input is Appreciated
May 8 '07 #5
Rabbit
12,516 Expert Mod 8TB
It's very bad design to have your dates as fields because it limits your ability to query the data.

Usually you would have one date field and the date the event occured would go in that field rather than making them their own field. In that case you can just query to the days you want and crosstab them into the column headings. But by designing them as columns, you remove that possibility.

Your only choice is to use an intermediary form that rewrites the querydef.SQL of the query to account for the date changing all the time.
May 8 '07 #6
Rabbit,

You’ve validated what I’ve though all along. Bad Design!! (Not mine)

You said “Your only choice is to use an intermediary form that rewrites the querydef.SQL” but I'm not 100% sure what you mean.

Do you mean create a form to manipulate the query? I’ve tried that but I’m not doing it right.

If that is the best way I will learn how to do it. I did it a long time ago and don't recall the the best approach. What do you think best approach for me is and/or best place to start.

Again thanks
May 8 '07 #7
Rabbit
12,516 Expert Mod 8TB
Rabbit,

You’ve validated what I’ve though all along. Bad Design!! (Not mine)

You said “Your only choice is to use an intermediary form that rewrites the querydef.SQL” but 100% what you mean.

Do you mean create a form to manipulate the query? I’ve tried that but I’m not doing it right.

If that is the best way I will learn how to do it. I did it a long time ago and don't recall the the best approach. What do you think best approach for me is and/or best place to start.

Again thanks
That's exactly what I mean. Seeing as how the column names are always changing depending on the date, you'll have to use VBA code. You'll basically get the query def and change it's SQL.
Expand|Select|Wrap|Line Numbers
  1. Dim qdf As QueryDef
  2. Set qdf = CurrentDb.QueryDefs("Query Name")
  3. qdf.SQL = "New SQL string"
  4.  
And the new SQL string will be built to take the current date and select the 5 dates before it.
May 8 '07 #8
Sorry I feel like an idiot. Where do I but the code?
I put in a VBA Module and all I get is errors. I haven’t used VB in a long time.

I did it like this EX: Table name "DAILY" with field "CATEGORY" and Query name "QUERY1" and I’m trying to sum 1 column named 4/26/2007

Private Sub SQLSTRING()
Dim qdf As QueryDef
Set qdf = CurrentDb.QueryDefs("QUERY1")
qdf.SQL = "SELECT [DAILY]. CATEGORY, Sum([DAILY].[4/26/2007]) AS [4/26/2007]"
End Sub

I know I’m doing this totally wrong!!

I always get an error at qdf.SQL

Do you want me to connect this to a combo box or command button on a form.

I feel so dumb, I should know this part. But i feel clueless

Thanks
May 8 '07 #9
Rabbit
12,516 Expert Mod 8TB
You forgot to tell it where to get the records. You need a FROM clause. You can't tell it to SELECT anything without telling it where to SELECT FROM.

And where you put it depends on when you want the query to run. Probably a button.
May 8 '07 #10
I still have figuired out what I just posted I just wanted to see why it is formatted the way it is.

Your thoughts Please

In the begining I tried to transpose the data but it didn't play nice if I did the whole thing I'd end up with 6000+ Columns. And the data is a mess.

See Below.
-------------------------------------------------------------------------------------------------------------
Category Hardware Hardware (Columns Names)
SubCategory hard drive Printer
Product Type boot error HP1234
Problem Type Won't Boot not mapped
4/20/2007 0 0
4/21/2007 0 1
4/22/2007 0 1
4/23/2007 2 2
4/24/2007 2 0
4/25/2007 0 4
-------------------------------------------------------------------------------------------------------------

Picture 6000+ Columns and years of data. This is why we formatted it the other way. and I'd have 3 or 4 hundred named Hardware, which i believe is impossible. I hate this project!!


Any Suggestions are appreciated !!!!!!!!!!.
May 8 '07 #11
You forgot to tell it where to get the records. You need a FROM clause. You can't tell it to SELECT anything without telling it where to SELECT FROM.

And where you put it depends on when you want the query to run. Probably a button.

I got an Error with the FROM in there I just copied the wrong version to you.
At least I'm getting there.

Thank you Very Much RABBIT. You have been a great help. I thought would require VB and some good VB to make it nice. But I needed to figuire it out my self. I've exhusted every angle but VB, didn't want to relearn it.
Like you said the DB is a bad design.
May 8 '07 #12
Rabbit
12,516 Expert Mod 8TB
I got an Error with the FROM in there I just copied the wrong version to you.
At least I'm getting there.

Thank you Very Much RABBIT. You have been a great help. I thought would require VB and some good VB to make it nice. But I needed to figuire it out my self. I've exhusted every angle but VB, didn't want to relearn it.
Like you said the DB is a bad design.
I can't tell if this means you don't need any more help, for now anyways.
May 8 '07 #13
I think you pointed me in the right direction. I don't need help now, unless you want to do eveything for me. I'm sure I'll come across some issues and will probably be back in a few days.

I got to learn some stuff on my own. More of a refresher of VB.

I have to say I've read so many of "thescripts" forums and they have help alot. Now that I join I'm even more impressed.

Thanks Rabbit
May 8 '07 #14
Rabbit
12,516 Expert Mod 8TB
I think you pointed me in the right direction. I don't need help now, unless you want to do eveything for me. I'm sure I'll come across some issues and will probably be back in a few days.

I got to learn some stuff on my own. More of a refresher of VB.

I have to say I've read so many of "thescripts" forums and they have help alot. Now that I join I'm even more impressed.

Thanks Rabbit
Not a problem.

I choose to take a more guided approach rather than writing out the solution.
Good luck. Let us know if you have any problems.
May 9 '07 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Greg | last post by:
I am working on a project that will have about 500,000 records in an XML document. This document will need to be queried with XPath, and records will need to be updated. I was thinking about...
5
by: Shane | last post by:
I wonder if someone has any ideas about the following. I am currently producing some reports for a manufacturing company who work with metal. A finished part can contain multiple sub-parts to...
1
by: Steve | last post by:
I have looked through the newsgroup for an answer to this but haven't been able to find anything resembling my situation. What I want to do is relatively simple, I think. I have a crosstab...
6
by: KashMarsh | last post by:
Trying to show running totals on a report, except it needs to show one total amount and values being subtracted from it. For example, the report shows a Total Inventory amount (TotInvAmt). And...
2
by: Greg | last post by:
I was wondering if there is a simple way to present a totals column in a bound datagrid where the totals aren't actually persisted (in my case to an xml file). Ideally, when I populate the datagrid...
10
by: Jim | last post by:
I'm sure this has been asked before but I can't find any postings. I have a table that has weekly inspections for multiple buildings. What I need to do is break these down by the week of the...
3
by: mochatrpl | last post by:
I am looking for a way to make a query / report display the running average for total dollars. I have already set up a query to provide totals dollars per day from which a report graphly shows...
1
newnewbie
by: newnewbie | last post by:
Every week I get an Excel file that needs to be modified to be imported in Access. Modification includes columns renaming, deleting some of them, changing their order and data type, etc. I...
2
by: hwalker | last post by:
Hello all. Long time reader, first time poster :) I'm creating a repot that shows "the last two weeks of data the next 6 weeks of data, week over week". So, I have a calculated field called...
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: 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?
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...
0
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,...
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.