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

Select only 12 columns going back - Dashboard_PV

106 100+
This thread is similar to the thread (Select only 10 columns going back) that I posted regarding the dynamic selection of data going back one month at a time for 12 months. Here is the qiote fron the other thread (#3) :
Basically what this is about is measuring the performance of employess in terms of how many errors they made this month and compare the current figure with the ones made before. For example, for employee A the number of errors for the Month of March 2008 is 324, for february 2008 is 420, for January 2008 is 200, etc....going all the back to the month of March 2007 and see how the errors have increased or decreased over time. The users of this application want to be able to do this by picking from any given month and look back up to a year in monthly increments
This time, the difference is in how the data from the table is presented. I constructed the table from a series of data dumps that are issued monthly. I select the column with the data that I want, called PV and rename the column for the month in which it came. For example, if I took a column corresponding to the month of January, the metadata would look like this:
Expand|Select|Wrap|Line Numbers
  1. Table Name=[1/31/2007]
  2. Field;    Type;    IndexInfo
  3. ID;       String;  
  4. Name;     String;    PK
  5. Approve;  Numeric
The Sample data looks like this:
Expand|Select|Wrap|Line Numbers
  1. ID    Name       Approve
  2. 1     LE_DH       4518
  3. 2     DONG_PA     3182 
  4. 3     DANG_HT     3175
and so on

I rename the fields Name to UserName and Approve to PV.
I then do a SQL join with tblMembers table, which has this structure:
Expand|Select|Wrap|Line Numbers
  1. Table Name=[tblMembers]
  2. Field;    Type;    IndexInfo
  3. MemberID; String;   PK
  4. Name;     String      
  5. UserName; String
  6. Initials; String
Here is some sample data:
Expand|Select|Wrap|Line Numbers
  1. MemberID   Name         UserName   Initials
  2. 1          Dang,Hong    dang_ht    htd
  3. 2          Dong,Patrick dong_pa    pdd
and so on

I then write sql for a right join between tblMembers and the built tables.
I add every table representing a month and I end up with a table which i called Dashboard_PV. Its structure is:
Expand|Select|Wrap|Line Numbers
  1. Table Name=[Dashboard_PV]
  2. Field; Type; IndexInfo
  3. Initials; String; PK
  4. UserName; String
  5. February2008; Numeric
  6. January2008; Numeric
  7. December2007; Numeric
here is some sample data:
Expand|Select|Wrap|Line Numbers
  1. Dashboard_PV
  2. Initials   UserName  February2008   January2008   December2007
  3. HTD        dang_ht      3165           4523          4043
  4. KKD        diep_kk      2528           2662          1409
and so on


I hope this is clear. I am not sure if I went about it the right way - your help is appreciated,


Richard
Apr 7 '08 #1
28 2351
NeoPa
32,556 Expert Mod 16PB
This post is to register.
Tonight I will just do some tidying up on the post adding links and adjusting the format somewhat. This is likely to be the main reference point so quite important.

At first look it seems as if you've made a decent attempt from which to start. Getting late now so I won't try to find any solutions tonight.
Apr 7 '08 #2
NeoPa
32,556 Expert Mod 16PB
Richard, before I head off for the night, if you have made up Dashboard_PV from other data sources, I suggest you reconsider the layout. This will be a real head-ache to work with and should be avoided if at all possible.

Let me know.
Apr 7 '08 #3
Rickster66
106 100+
This post is to register.
Tonight I will just do some tidying up on the post adding links and adjusting the format somewhat. This is likely to be the main reference point so quite important.

At first look it seems as if you've made a decent attempt from which to start. Getting late now so I won't try to find any solutions tonight.
That's fine, thanks so much
Apr 7 '08 #4
Rickster66
106 100+
That's fine, thanks so much
I just got note from my bosses about a new requirement regarding the last post. Should I post it here or there. I've been trying to work with it but it's not working.

Richard
Apr 7 '08 #5
NeoPa
32,556 Expert Mod 16PB
I suspect you meant to say "the last thread" rather than "the last post". If so, then that thread is where it needs to be posted.

While I'm here, can I direct your attention back to post #3 and request a response. Does your new table need to be in this un-database like format?
Apr 8 '08 #6
Rickster66
106 100+
I suspect you meant to say "the last thread" rather than "the last post". If so, then that thread is where it needs to be posted.

While I'm here, can I direct your attention back to post #3 and request a response. Does your new table need to be in this un-database like format?
The new table does not need to be in the un-database-like format. If you think that it should be in database-like format or not is perfectly fine.
Apr 8 '08 #7
Rickster66
106 100+
Richard, before I head off for the night, if you have made up Dashboard_PV from other data sources, I suggest you reconsider the layout. This will be a real head-ache to work with and should be avoided if at all possible.

Let me know.
I absolutely have no problem reconsidering the layout. At this moment, I can't think of another type of redesign.
Apr 8 '08 #8
NeoPa
32,556 Expert Mod 16PB
How about :
Expand|Select|Wrap|Line Numbers
  1. Table Name=[Dashboard_PV]
  2. Field; Type; IndexInfo
  3. Initials; String; PK
  4. MonthInd; String; PK
  5. PV; Numeric
NB. [MonthInd] is a STRING field and NOT a date/time one. The format for this data must be EXACTLY "yyyymm". If this is not possible then we can extract the data with the month as previously displayed then update it with an UPDATE query.
Also, there is no need for a [UserName] field if this is already available in [tblMembers].
Here is some sample data:
Expand|Select|Wrap|Line Numbers
  1. [Dashboard_PV]
  2. Initials   MonthEnd      PV
  3. HTD        200802     3,165
  4. HTD        200801     4,523
  5. HTD        200712     4,043
  6. KKD        200802     2,528
  7. KKD        200801     2,662
  8. KKD        200712     1,409
  9. ...
Apr 9 '08 #9
Rickster66
106 100+
How about :
Expand|Select|Wrap|Line Numbers
  1. Table Name=[Dashboard_PV]
  2. Field; Type; IndexInfo
  3. Initials; String; PK
  4. MonthInd; String; PK
  5. PV; Numeric
NB. [MonthInd] is a STRING field and NOT a date/time one. The format for this data must be EXACTLY "yyyymm". If this is not possible then we can extract the data with the month as previously displayed then update it with an UPDATE query.
Also, there is no need for a [UserName] field if this is already available in [tblMembers].
Here is some sample data:
Expand|Select|Wrap|Line Numbers
  1. [Dashboard_PV]
  2. Initials   MonthEnd      PV
  3. HTD        200802     3,165
  4. HTD        200801     4,523
  5. HTD        200712     4,043
  6. KKD        200802     2,528
  7. KKD        200801     2,662
  8. KKD        200712     1,409
  9. ...
I finished constructing the table as you specified
Apr 11 '08 #10
NeoPa
32,556 Expert Mod 16PB
Right, if you could post clearly what you need it to do now, then we can look at the problem.

I couldn't get this from your first post. It seemed to stop after saying that it was different from the other thread.
Apr 11 '08 #11
Rickster66
106 100+
Right, if you could post clearly what you need it to do now, then we can look at the problem.

I couldn't get this from your first post. It seemed to stop after saying that it was different from the other thread.
Very well, what I need is to be able to pull a list of data from the newly done Dashboard_PV table using date parameters and initials. The data should be displayed month by month going backwards 12 months. The column MonthEnd in the table Dashboard shows (with a text datatype) monthly information as it is. This is what result should look like:
Asssuming the query was run with parameters for Stats.txtcurrentdate and Stats.cbInitials:
Expand|Select|Wrap|Line Numbers
  1. PV                     Month
  2. 1458                  January  2008
  3. 1299                  December  2007
  4. 1499                  November  2007
  5. 1320                  October  2007
  6. 1277                  September  2007
  7. 1322                  August  2007
  8. 1889                  July  2007
  9. .                         .
  10. 2998                  January 2007
I can see Dashboard_PV's structure is very similar to this sample. The issue is that must go back 12 months. So this is what I need to get done. the next step would be to calculate the percentage of the MEQA/PV going back 3, 6, 9 and 12 months back.
Apr 11 '08 #12
Rickster66
106 100+
hello I hope you haven't forgotten my situation
Apr 15 '08 #13
NeoPa
32,556 Expert Mod 16PB
This one I didn't even catch, so haven't yet had an opportunity to forget ;)

I was away over the weekend so maybe that explains why. I will try to look again soon. All pretty busy at the moment I'm afraid.
Apr 15 '08 #14
NeoPa
32,556 Expert Mod 16PB
Try the following :
Expand|Select|Wrap|Line Numbers
  1. SELECT Format(subD.Month,'mmmm yyyy') AS [Month],
  2.        subH.PV
  3. FROM (SELECT DateAdd('m',-[DateOffset],Forms!Stats.txtCurrentDate) AS Month,
  4.              Format([Month],'yyyymm') AS YM
  5.       FROM tblDate
  6.       WHERE [DateOffset]<n) AS subD LEFT JOIN
  7.      (SELECT [PV],
  8.              [MonthEnd]
  9.       FROM Dashboard_PV
  10.       WHERE (([Initials]=Forms!Stats.cbInitials)
  11.         AND  ([PV1]='Mail Service'))) AS subH
  12.   ON subD.YM=subH.MonthEnd
  13. ORDER BY subD.Month DESC
It assumes the same values (0 to 12) in the [tblDate] table ([DateOffset]).
n (line #5) is the value of the number of months you need (3; 6; 9; 12 etc).
Apr 16 '08 #15
Rickster66
106 100+
Try the following :
Expand|Select|Wrap|Line Numbers
  1. SELECT Count(subH.MEQA) AS [Count], Format(subD.Month,'mmmm yyyy') AS [Month]
  2. FROM (SELECT DateAdd('m',-[DateOffset],Forms!Stats.txtCurrentDate) AS Month,
  3.              Format([Month],'yyyymm') AS YM
  4.       FROM tblDate
  5.       WHERE [DateOffset]<n) AS subD LEFT JOIN
  6.      (SELECT [PV],
  7.              [MonthEnd]
  8.       FROM Dashboard_PV
  9.       WHERE (([Initials]=Forms!Stats.cbInitials)
  10.         AND  ([PV1]='Mail Service'))) AS subH
  11.   ON subD.YM=subH.MonthEnd
  12. ORDER BY subD.Month DESC
It assumes the same values (0 to 12) in the [tblDate] table ([DateOffset]).
n (line #5) is the value of the number of months you need (3; 6; 9; 12 etc).
I ran the code:
Expand|Select|Wrap|Line Numbers
  1. SELECT Count(([subH].[MEQA])) AS [Count], Format(subD.Month,'mmmm yyyy') AS [Month]
  2. FROM [SELECT DateAdd('m',[DateOffset],Forms!Stats.txtCurrentDate) AS Month,
  3.              Format([Month],'yyyymm') AS YM
  4.       FROM tblDate
  5.       WHERE [DateOffset]<n]. AS subD LEFT JOIN [SELECT [PV],
  6.              [MonthEnd]
  7.       FROM Dashboard_PV
  8.       WHERE (([Initials]=Forms!Stats.cbInitials)
  9.         AND  ([PV1]='Mail Service'))]. AS subH ON subD.YM = subH.MonthEnd
  10. GROUP BY Format(subD.Month,'mmmm yyyy'), subD.Month
  11. ORDER BY subD.Month DESC;
after removing the "-" because it already exists on the tblDate table. It asked for several parameters:
I entered

...txtcurrentdate: 4/1/2008
...n :3 or 6 or 9 or 12
...PV1 Mail Service
...subH.MEQA 1? 3? (not sure what to enter here because MEQA information should come from tblProtohistory, which does not appear in this query - Dashboard_PV is PV data with Month without Mail Service parameters - my apologies if I failed to mention this before) what I get then is:
Expand|Select|Wrap|Line Numbers
  1.   Count    Month
  2. 1    April 2008
  3. 1    March 2008
  4. 1    February 2008
  5. 1    January 2008
  6. 1    December 2007
  7. 1    November 2007
  8. 1    October 2007
  9. 1    September 2007
  10. 1    August 2007
  11. 1    July 2007
  12. 1    June 2007
  13. 1    May 2007
  14. 1    April 2007
  15.  
Not sure what to make of this
My gratitude as always,

Richard
Apr 17 '08 #16
NeoPa
32,556 Expert Mod 16PB
I've literally just had a second to look at this and the code I posted was sloppy. I was a little pushed for time yesterday so didn't check it as carefully as usual.

You will notice though, that there is an explanation for the "n" in the SQL later in the post.

I do need to ask - where in the table is the data to enable us to filter by the "Mail service" value?
Apr 17 '08 #17
Rickster66
106 100+
I've literally just had a second to look at this and the code I posted was sloppy. I was a little pushed for time yesterday so didn't check it as carefully as usual.

You will notice though, that there is an explanation for the "n" in the SQL later in the post.

I do need to ask - where in the table is the data to enable us to filter by the "Mail service" value?
I understand the functiion n plays in the query.
"Mail Service" and "PSC" is part of the MEQA data and its table is tblprotohistory. Both Mail service and psc data are under a column named: "PV1." The table Dashboard_PV data does not have "Mail Service" or "PSC" data. I hope this answers your question, if it does not, I would appreciate it if you rephrase it for me.

Many thanks,


Richard
Apr 17 '08 #18
Rickster66
106 100+
There's something else I wanted to add. I noticed that everytime I change anything in the sql code, even if I change it back, I'll get an error: "Invalid bracketing of name 'SELECT DateAdd('m', [DateOffset'. " Is there something that I can do to avoid this?
Apr 17 '08 #19
NeoPa
32,556 Expert Mod 16PB
Here we get into Access specific territory. This has come up a few times so I've knocked up a little article on it that you can refer to (Access QueryDefs Mis-save Subquery SQL).
Apr 18 '08 #20
NeoPa
32,556 Expert Mod 16PB
Try the following :
Expand|Select|Wrap|Line Numbers
  1. SELECT Format(subD.Month,'mmmm yyyy') AS [Month],
  2.        subH.PV
  3. FROM (SELECT DateAdd('m',[DateOffset],Forms!Stats.txtCurrentDate) AS Month,
  4.              Format([Month],'yyyymm') AS YM
  5.       FROM tblDate
  6.       WHERE [DateOffset]>-n) AS subD LEFT JOIN
  7.      (SELECT [PV],
  8.              [MonthEnd]
  9.       FROM Dashboard_PV
  10.       WHERE [Initials]=Forms!Stats.cbInitials) AS subH
  11.   ON subD.YM=subH.MonthEnd
  12. ORDER BY subD.Month DESC
Apr 18 '08 #21
Rickster66
106 100+
Here we get into Access specific territory. This has come up a few times so I've knocked up a little article on it that you can refer to (Access QueryDefs Mis-save Subquery SQL).
I am reading it now you explanationa are helping me make sense of this complex sql process.
Apr 18 '08 #22
Rickster66
106 100+
Try the following :
Expand|Select|Wrap|Line Numbers
  1. SELECT Format(subD.Month,'mmmm yyyy') AS [Month],
  2.        subH.PV
  3. FROM (SELECT DateAdd('m',[DateOffset],Forms!Stats.txtCurrentDate) AS Month,
  4.              Format([Month],'yyyymm') AS YM
  5.       FROM tblDate
  6.       WHERE [DateOffset]>-n) AS subD LEFT JOIN
  7.      (SELECT [PV],
  8.              [MonthEnd]
  9.       FROM Dashboard_PV
  10.       WHERE [Initials]=Forms!Stats.cbInitials) AS subH
  11.   ON subD.YM=subH.MonthEnd
  12. ORDER BY subD.Month DESC
It works!! I get the desired results. Thank you
Apr 18 '08 #23
NeoPa
32,556 Expert Mod 16PB
Excellent :)

I've been tied up over the weekend so I've only just caught this.

Just to confirm, this one can be put to bed and we can concentrate on the other for a while yes?
Apr 21 '08 #24
Rickster66
106 100+
Excellent :)

I've been tied up over the weekend so I've only just caught this.

Just to confirm, this one can be put to bed and we can concentrate on the other for a while yes?
Yes sir, that is correct - thank you again
Apr 21 '08 #25
Rickster66
106 100+
Yes sir, that is correct - thank you again

My boosses are pleased.

Richard
Apr 23 '08 #26
NeoPa
32,556 Expert Mod 16PB
I'm very pleased to hear it Richard :)

I haven't forgotten the other one still - I just need a bit longer time to deal with such a complex question ;)
Apr 24 '08 #27
Rickster66
106 100+
I'm very pleased to hear it Richard :)

I haven't forgotten the other one still - I just need a bit longer time to deal with such a complex question ;)
That's good - as long as you don't for me please......

Richard
Apr 25 '08 #28
NeoPa
32,556 Expert Mod 16PB
Not forgotten. I will try to find enough time tomorrow.
Apr 25 '08 #29

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

Similar topics

6
by: RCS | last post by:
I've been running into more and more complexity with an application, because as time goes on - we need more and more high-level, rolled-up information. And so I've created views, and views that use...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
5
by: rAinDeEr | last post by:
Hi, I have a web application with a table to store terms and conditions of a Company. This may some times run into many pages and some times it may be just a few sentences. It is a character...
48
by: Jimmy | last post by:
thanks to everyone that helped, unfortunately the code samples people gave me don't work. here is what i have so far: <% Dim oConn, oRS, randNum Randomize() randNum = (CInt(1000 * Rnd) + 1) *...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
101
by: Rickster66 | last post by:
I need to create a sql statement in MS Access from only the last 12 columns a table that has has dates (the last days of the month) as the names of the columns. In actuality, each column is part of ...
22
by: Rickster66 | last post by:
As Instructed this is a new thread regarding my original post: "Select Only 10 Columns Going Back" I'm sorry for the late response. I've been gathering up information and carefully with as much...
17
by: trose178 | last post by:
Good day all, I am working on a multi-select list box for a standard question checklist database and I am running into a syntax error in the code that I cannot seem to correct. I will also note...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.