473,385 Members | 1,772 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.

Select Only 10 Columns Going Back

106 100+
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 table that is sent to my office monthly. I only use one particular column and discard the rest. The columns in the table then looks like this:
Expand|Select|Wrap|Line Numbers
  1. 2_29_2008 || 1_31_2007 || 12_31_2007  11_30_2007 10_31_2007 ...etc.....1_31_2007
I need to be able to select any month dynamically and select the last 12 months only.

Another idea is to use the whole tables but I the requirement is that the last 12 months must be gathered. What it basically shows is the number of errors made by a person, so the previous months represent previous performance.

I am very desperate, any help is greatly appreciated!

Richard
Mar 12 '08 #1
101 6747
NeoPa
32,556 Expert Mod 16PB
Are you creating (expecting to create) the SQL statement in code?
This can be done using code but might be fiddly. A clearer indication of exactly what you're dealing with is likely to be crucial.
Mar 13 '08 #2
Rickster66
106 100+
Are you creating (expecting to create) the SQL statement in code?
This can be done using code but might be fiddly. A clearer indication of exactly what you're dealing with is likely to be crucial.
Yes the SQL statement is to be created in code. 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
and measure performance. I thought of creating arrays for each month but something goes wrong......
Mar 13 '08 #3
NeoPa
32,556 Expert Mod 16PB
How many columns are there then in the data?
Is the number fixed?
How are they positioned relative to the current month (Month(Date()))?
Where is the code to run from?
What is the SQL that you want as a result of a run done now?

With these answers we can look at how to produce the SQL relative to the data required.
Mar 13 '08 #4
Rickster66
106 100+
How many columns are there then in the data?
Is the number fixed?
How are they positioned relative to the current month (Month(Date()))?
Where is the code to run from?
What is the SQL that you want as a result of a run done now?

With these answers we can look at how to produce the SQL relative to the data required.
Great! there are 12 columns in the table. They are positioned stating from the very first month and year. For example, If the current month is March 2008, then next month will be March 2007, then April 2007, May 2007, June 2008, etc....finishing in March 2008.

The code can run from a form or by way of a query. This is what I have written so far ...based on fake data :
Expand|Select|Wrap|Line Numbers
  1. SELECT UserName,
  2.        Count([January  2007]) AS [Jan  2007],
  3.        Count([February  2007]) AS [Febuary  2007],
  4.        Count([March  2007]) AS [Mrch  2007],
  5.        Count([April  2007 ]) AS [Aprl  2007],
  6.        Count([May  2007 ]) AS [My  2007],
  7.        Count([June  2007 ]) AS [Jun  2007],
  8.        Count([July  2007]) AS [Jul  2007],
  9.        Count([August   2007]) AS [Aug   2007],
  10.        Count([September  2007 ]) AS [Sept  2007],
  11.        Count([November  2007 ]) AS [Nov  2007],
  12.        Count([December  2007 ]) AS [Dec  2007],
  13.        Count([January  2008]) AS [Jan  2008],
  14.        Count([February  2008]) AS [Feb  2008]
  15. FROM xtbMEQA_MONTH
  16. GROUP BY UserName;
I created a crosstab query then added date functions from the original date column that received the date of the error. This was one column that had many rows of dates. The cross tab column took care of the rest -- this is all I could think of.
Mar 13 '08 #5
NeoPa
32,556 Expert Mod 16PB
Sorry, had a busy Admin evening so may need to get to this tomorrow.
If you don't see a further reply tomorrow please * Bump * the thread as a reminder.
Mar 13 '08 #6
Rickster66
106 100+
I'm not sure If I did this the way to BUMP a message but here it goes :
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 table that is sent to my office monthly. I only use one particular column and discard the rest. The columns in the table then looks like this:

Code: ( text )
2_29_2008 || 1_31_2007 || 12_31_2007 11_30_2007 10_31_2007 ...etc.....1_31_2007

I need to be able to select any month dynamically and select the last 12 months only.

Another idea is to use the whole tables but I the requirement is that the last 12 months must be gathered. What it basically shows is the number of errors made by a person, so the previous months represent previous performance.

I am very desperate, any help is greatly appreciated!

Richard

This what I wrote at the beginning tof the thread
Mar 14 '08 #7
Rickster66
106 100+
Someone suggested using getrows with ubound or maybe the fields.count preoperty........any thoughts?
Mar 14 '08 #8
NeoPa
32,556 Expert Mod 16PB
Bumping is simply adding a new post (contents irrelevant) so that the thread moves up to the top (most recently added to) in the list of threads.

Don't worry, I will catch up with this today (or tomorrow latest) and answer the original question first. I always try to work in order. Extra questions can wait until I've covered the outstanding ones at least.

I haven't forgotten you ;)
Mar 14 '08 #9
Rickster66
106 100+
Thank you very much. I really appreciate it

Richard
Mar 14 '08 #10
NeoPa
32,556 Expert Mod 16PB
Right, I went back to post #5 and I had to reformat your SQL to be able to read it. The effect is unchanged btw.
Unfortunately, I suspect there's something not quite right with processing the results of a crosstab the way you have proposed. It seems to me that the crosstab would produce the sort of figures you are after without needing to GROUP by the [UserName].

Can you post in some sample data for the crosstab query so I can get a feel for the sort of data we're dealing with? Are there more than one lines for each [UserName]?

BTW, what is going on with the names of the fields in there? There are various with extra spaces, both within and at the end of field names, as well as some very unusual abbreviations that are supposed to represent months. This may not seem important now, but it will soon when we try to get the code to produce your SQL for you.
Mar 14 '08 #11
Rickster66
106 100+
Right, I went back to post #5 and I had to reformat your SQL to be able to read it. The effect is unchanged btw.
Unfortunately, I suspect there's something not quite right with processing the results of a crosstab the way you have proposed. It seems to me that the crosstab would produce the sort of figures you are after without needing to GROUP by the [UserName].

Can you post in some sample data for the crosstab query so I can get a feel for the sort of data we're dealing with? Are there more than one lines for each [UserName]?

BTW, what is going on with the names of the fields in there? There are various with extra spaces, both within and at the end of field names, as well as some very unusual abbreviations that are supposed to represent months. This may not seem important now, but it will soon when we try to get the code to produce your SQL for you.
Here's some sample data from the query:
Expand|Select|Wrap|Line Numbers
  1.  UserName    1/31/2007    2/28/2007    3/31/2007    4/30/2007
  2. dang_ht    3175    2647    3440    3966
  3. desai_ra    1477    916    1365    2243
  4. diep_kk    1828    2911    3490    2482
  5. diep_tk    1952    1617    1105    1808
  6. djauhar_aj    1828    1913    1215    165
  7. fazeli_np    1727    3276    2003    1785
  8. guirgui_es    2065    2407    2561    2402
  9. hoang_cq    1082    506    1255    1146
  10. hoang_hn        1324    1836    1863
  11. huynh_cn    1460    863    497    444
  12. juson_kn        1495    2961    1815
  13. lam_at    1483    1439    2216    2741
  14. lam_mu    1732    1628    2207    1965
  15. lam_td        2082    4291    1668
  16. lau_sc    2350    2572    1473    4022
  17. le_am    1627    1393    1789    2173
  18. lee_ee    1673    2643    2456    2347
  19. lee_jy        1266    3509    1600
  20. lee_ke    1919    2421    1511    1179
  21. lui_ey    2214    360    1506    1578
  22. luong_dn    1509    1068    1005    1242
  23. mackey_yr    2056    1392    1432    1073
  24. mai_jm        87    1791    1134
  25. martino_gc    2668    1791    1104    1191
  26. nemeh_ga                1
  27. nghiem_tn    1684    2895    3335    3030
  28. nguyen_ad        965    2416    1084
  29. nguyen_al    1308    1438    1861    2360
  30. nguyen_ct        876    1883    1456
  31. nguyen_ea        1132    2587    1248
  32. nguyen_ja                1
  33.  
  34.  
I have another query that needs to be handled in the same manner (rolling dynamically as described below. This other one is a type of errors data that each user has generated. The data I just posted is the more broad type of errors that the users have generated ( I hope I'm not confusing you too much)the other data loos like this:
Expand|Select|Wrap|Line Numbers
  1.  
  2. Initials    MEQA    Month                   DateReceived
  3. EYL    1    January  2008    1/15/2008
  4. EJW    1    January  2008    1/15/2008
  5. EAN    4    June  2007     6/13/2007
  6. AMN    1    June  2008                    6/12/2008
  7. EAN    1    June  2008     6/12/2008
  8. AMN    3    March  2007    3/4/2007
  9. AMN    1    March  2007    3/6/2007
  10. EYL    1    March  2008    3/10/2008
  11. EJW    1    March  2008    3/7/2008
It is from this point that I created the crosstab queries.
I can also show you the crosstab queries too.

Thanks,
Richard
Mar 17 '08 #12
Rickster66
106 100+
Right, I went back to post #5 and I had to reformat your SQL to be able to read it. The effect is unchanged btw.
Unfortunately, I suspect there's something not quite right with processing the results of a crosstab the way you have proposed. It seems to me that the crosstab would produce the sort of figures you are after without needing to GROUP by the [UserName].

Can you post in some sample data for the crosstab query so I can get a feel for the sort of data we're dealing with? Are there more than one lines for each [UserName]?

BTW, what is going on with the names of the fields in there? There are various with extra spaces, both within and at the end of field names, as well as some very unusual abbreviations that are supposed to represent months. This may not seem important now, but it will soon when we try to get the code to produce your SQL for you.
As far as the abbreviations is concerned, I had no specific reason behind it - I will write them out if you think that is a better idea.
Mar 17 '08 #13
Rickster66
106 100+
As far as the abbreviations is concerned, I had no specific reason behind it - I will write them out if you think that is a better idea.
One more thing - the spaces indicate that no data was generated for that person for that month. Most likely because they were hired later in the year or perhaps they were on leave or some other similar thing.

Once again thank you so much!
Richard
Mar 17 '08 #14
Rickster66
106 100+
Right, I went back to post #5 and I had to reformat your SQL to be able to read it. The effect is unchanged btw.
Unfortunately, I suspect there's something not quite right with processing the results of a crosstab the way you have proposed. It seems to me that the crosstab would produce the sort of figures you are after without needing to GROUP by the [UserName].

Can you post in some sample data for the crosstab query so I can get a feel for the sort of data we're dealing with? Are there more than one lines for each [UserName]?

BTW, what is going on with the names of the fields in there? There are various with extra spaces, both within and at the end of field names, as well as some very unusual abbreviations that are supposed to represent months. This may not seem important now, but it will soon when we try to get the code to produce your SQL for you.
Please forgive for the confusion but the department has changed its miond. They now want the data the be able to be pulled dynamically as before using the same rules as before but they are to be display in the following manner:
for a given person:
Expand|Select|Wrap|Line Numbers
  1. MEQA    Month
  2. 1    January  2008
  3. 1    December  2007
  4. 4    November  2007
  5. 1    October  2007
  6. 1    September  2007
  7. 3               August  2007
  8. 1    July  2007
  9. .               .
  10. 1    January 2007 
-- They just gave me this and I am just as clueless

Richard
Mar 17 '08 #15
NeoPa
32,556 Expert Mod 16PB
Richard, I've had a horribly busy day and evening so I've been unable to catch up with all the technical posts that are outstanding.

I hope to catch up with all these posts tomorrow so please bear with me and I will respond to all you've posted.
Mar 18 '08 #16
Rickster66
106 100+
Richard, I've had a horribly busy day and evening so I've been unable to catch up with all the technical posts that are outstanding.

I hope to catch up with all these posts tomorrow so please bear with me and I will respond to all you've posted.
No problem, That's fine - Thanks for letting me know,

Richard
Mar 18 '08 #17
NeoPa
32,556 Expert Mod 16PB
Well, it seems that grouping by UserName would be entirely redundant as there is only one record per UserName anyway.

The spaces I was talking about were the spaces within the names of the months. Access provides ways to produce various standard forms of date text which we can use if we don't have to match the format in your earlier post.
Mar 18 '08 #18
NeoPa
32,556 Expert Mod 16PB
Your source data looks interesting.
Expand|Select|Wrap|Line Numbers
  1. Initials  MEQA  Month         DateReceived
  2. EYL         1   January 2008  1/15/2008
  3. EJW         1   January 2008  1/15/2008
  4. EAN         4   June 2007     6/13/2007
  5. AMN         1   June 2008     6/12/2008
  6. EAN         1   June 2008     6/12/2008
  7. AMN         3   March 2007    3/4/2007
  8. AMN         1   March 2007    3/6/2007
  9. EYL         1   March 2008    3/10/2008
  10. EJW         1   March 2008    3/7/2008
I presume that the initials link into another table with the UserNames in.

I don't think I know where MEQA comes into things though. As this is involved in the new layout perhaps you could explain.
Mar 18 '08 #19
Rickster66
106 100+
Your source data looks interesting.
Expand|Select|Wrap|Line Numbers
  1. Initials  MEQA  Month         DateReceived
  2. EYL         1   January 2008  1/15/2008
  3. EJW         1   January 2008  1/15/2008
  4. EAN         4   June 2007     6/13/2007
  5. AMN         1   June 2008     6/12/2008
  6. EAN         1   June 2008     6/12/2008
  7. AMN         3   March 2007    3/4/2007
  8. AMN         1   March 2007    3/6/2007
  9. EYL         1   March 2008    3/10/2008
  10. EJW         1   March 2008    3/7/2008
I presume that the initials link into another table with the UserNames in.

I don't think I know where MEQA comes into things though. As this is involved in the new layout perhaps you could explain.
Actually what would happen is that the user would select a member then a date then click find. The data would appear like this: Lets say January 2008 was picked.


Expand|Select|Wrap|Line Numbers
  1. MEQA     Month  
  2.     1      January 2008  
  3.     1      December 2007  
  4.     4      November 2007     
  5.     1      October 2007    
  6.    1       September 2007     
  7.    3       August 2007   
  8.    1       July 2007    
  9.    1       June 2007   
  10.    1       May 2007  
  11.    2       April 2007
  12.    1       March 2007
  13.   3         February  2007
  14.   2         January 2007   
So as you can see, for every date picked, There must be a show of data that goes back 12 months. MEQA is simply a severe error commited by the user.
Mar 18 '08 #20
Rickster66
106 100+
Hi NeoPa - Did you forget me?
Mar 19 '08 #21
NeoPa
32,556 Expert Mod 16PB
No - Not forgotten.
Things have just been really busy recently on the site. As an Admin I sometimes get tied up with less visible issues.

I will get back to this as soon as I can. Easter weekend may enable me to catch up a bit.
Mar 20 '08 #22
NeoPa
32,556 Expert Mod 16PB
Your data doesn't have a UserName included in it anywhere. Unless there is some correlation between Initials and UserName, the data cannot be selected by UserName as you suggest.
  1. What is there that can be considered to be a unique identification in the data? Initials and Month perhaps.
  2. What is the data type of your fields [Month] & [DateReceived]?
  3. Lastly, how would the data be displayed? In a form? In a report? In a simple query window?
Clearly we need to have a query of some sort in the solution and the WHERE clause or filter (which is similar) must be designed to select only those items that you need. Without the information though, it's unclear how this can be achieved so I can't take this further just yet.
Mar 20 '08 #23
Rickster66
106 100+
Your data doesn't have a UserName included in it anywhere. Unless there is some correlation between Initials and UserName, the data cannot be selected by UserName as you suggest.

What is there that can be considered to be a unique identification in the data? Initials and Month perhaps.

What is the data type of your fields [Month] & [DateReceived]?

Lastly, how would the data be displayed? In a form? In a report? In a simple query window?

Clearly we need to have a query of some sort in the solution and the WHERE clause or filter (which is similar) must be designed to select only those items that you need. Without the information though, it's unclear how this can be achieved so I can't take this further just yet.
The idea is that the data is selected by initials within a subreport. The initials link the child and parent form (the is how the data is given to me - username is also included but I don't think it work with the parent form.

So, the data would be displayed in a report - Month and date received should be date types. Date received is just a timestamp so it doesn't need to show on the final output - i don't know if it would be a good idea to make it part of the query - if you think it should be part then it shall be.

If you need me to clarify more information, please let me know and thanks for all your help.

Richard

PS I've reading up on PIVOT CHARTS (I have know experience on this area) do you think it be worth it to check it out?
Mar 20 '08 #24
NeoPa
32,556 Expert Mod 16PB
I've edited post #23 to display my questions in a proper, numbered list.

It appears that you've answered question #2, but #1 & #3 are still awaiting answers.

Pop the answers to those in and we'll see if we can't knock up something a little more appropriate for your needs.
Mar 21 '08 #25
Rickster66
106 100+
I've edited post #23 to display my questions in a proper, numbered list.

It appears that you've answered question #2, but #1 & #3 are still awaiting answers.

Pop the answers to those in and we'll see if we can't knock up something a little more appropriate for your needs.
For question 1:
Expand|Select|Wrap|Line Numbers
  1. What is there that can be considered to be a unique identification in the data? Initials and Month perhaps.
I've been trying to figure that out myself. By that, I mean the the first table is a collection of of other tables that contain all sorts of data that is useless to me. I wrote a series of select into queries and came up with a table that looks like this:
Expand|Select|Wrap|Line Numbers
  1. Initials    2_29_2008     1/31/2008      12/31/2007  etc, etc......
  2. HTD    3165     4523      4043
  3. KKD    2528     2662      1409
  4. TKD    2204     2388      1788
  5. NPF    3625     5395      3615
  6. ESG    3714     4600      2487
  7. CQH    2089     2919      1503
  8. HNH    1895     1907      1331
  9. CNH    39     246       239
  10. etc.......
  11.  
and I thought the PK would be Initials. but since te requirement is that is should be displauyed in report form in columnar form:
Expand|Select|Wrap|Line Numbers
  1. Dates          HTD
  2. 12/31/2007      4043
  3. 11/30/2007      1904
  4. 10/31/2007      2049
  5. 9/30/2007          1862
  6. 8/31/2007          2957
  7. 7/31/2007          3516
  8. 6/30/2007        3871
  9. 5/31/2007          4115
  10. 4/30/2007          3966
  11. 3/31/2007          3440
  12. 2/28/2007          2647
  13. 1/31/2007          3175
What I did is transform the table so that the date columns were shown horizontally and the initials were shown vertically:

Expand|Select|Wrap|Line Numbers
  1. Dates    HTD    KKD    TKD
  2. 2/29/2008    3165    2528    2204
  3. 1/31/2008    4523    2662    2388
  4. 12/31/20071815    4043    1409    
  5. 11/30/2007 1460    1904    1753    
  6. 10/31/2007  680    2049    1943    
  7. 9/30/2007    1862    2218    1532
  8. 8/31/2007    2957    2102    1966
  9. 7/31/2007    3516    2668    617
  10. 6/30/2007    3871    2504    1557
  11. 5/31/2007    4115    2138    1720
  12. 4/30/2007    3966    2482    1808
  13. 3/31/2007    3440    3490    1105
  14. 2/28/2007    2647    2911    1617
  15. 1/31/2007    3175    1828    1952
  16.  
I still don't know if this is a good idea or not - as far as the dates is concerned, I did not convert the full dates to months yet- I figured I can do that at the very end. In terms of a unique identifier, would the dates column be fit enough to work as a unique identifier? I am pressuming but I am not sure. What would you suggest?


3) The data would be displayed in a report.

As always, thank you so much - this is beginning to make sense for me

Richard
Mar 24 '08 #26
NeoPa
32,556 Expert Mod 16PB
Sorry Richard. I'm getting confused here a little (Question 1). Q2 & 3 are fine, but I was talking about the data laid out in my post #19 that you posted originally in post #12.

I suppose what I really need to know is "Is it possible for the initials, matched with any particular month, appear more than once?"

EG. Is the following possible (where EYL / Jan 2008 appears more than once)?
Expand|Select|Wrap|Line Numbers
  1. Initials  MEQA  Month         DateReceived
  2. EYL         1   January 2008  1/15/2008
  3. EYL         5   January 2008  1/17/2008
  4. EYL         4   June 2007     6/13/2007
  5. AMN         1   June 2008     6/12/2008
This was the data source I was thinking of working with but your focus seems to be elsewhere so I'm hoping this is still valid.

If that is possible data then the query needs to have a GROUP BY clause and is complicated by aggregate functions etc. As a proponent of KISS I'm trying not to overcomplicate things.
Mar 25 '08 #27
Rickster66
106 100+
The initials matched to a particular month cannot appear more than once. Sorry for not making it clear.
Mar 26 '08 #28
NeoPa
32,556 Expert Mod 16PB
Right, I've just skimmed through the thread to remind myself what the basic request is (we've spent a while nailing down some details) so let me see if I can outline what I think we need and you can confirm this as I look at knocking something up. If, in the mean time, you can provide any real-life names for items that I'm using that would also help.

You have a form (name) where the operator will select a user (initials) and a month.
When the command button is clicked, a query (or report) should be run to produce lines, in descending order of month, to show thirteen months of MEQA data for the user where the first record (latest month) matches the month on the form.

Names required :
Form
Control where initials entered/selected
Control where month entered/selected
Command button that triggers the query/report
Table
Fields assumed to be [Initials]; [MEQA]; [Month]

One last question is :
What is the field type of [Month]?
This is treated differently depending on whether it's a Date/Time field or a Text field.

PS. Just to clarify - the first two and the last paragraphs are the most important as far as responses are concerned. I can get by without the names (I'll invent my own) but I do need confirmation I'm on the right lines and I need to know how to deal with the [Month] data.
Mar 27 '08 #29
Rickster66
106 100+
In terms of names for real life items I have:

Names required :
Form ....frmstats

Control where initials entered/selected.....cbInitials - the rowsource property will by a table that will fill out the combobox with initials
Control where month entered/selected - PVDate where when clicked, a calendar appears and the user selects a desired date. next to it is a non visible text box called EndDate - this textbox is populated automatically by ways of a function that picks up the date chosen from PVDate. the sql statement grabs these 2 dates as parameters and runs it.

Command button that triggers the query/report : cmdFind - when clicked, it it call the sql statement which will grab the parameters and run the query.

Table: tblHistory


Fields assumed to be [Initials]; [MEQA]; [Month] - this is correct

Month -I am presuming ought to be a date/Time type - I wonder how could the parameters work if it was to be a text field. I figure a format function for would change date date from say 3/5/2007 to March 2007 right at the textbox on the report - I hope this makes sense
Mar 27 '08 #30
NeoPa
32,556 Expert Mod 16PB
In the absense of confirmation relating to the first two paragraphs, I will continue as if you have read them and agree that they are on the button.

You talk about [PVDate] & [EndDate] controls and [EndDate] being populated from [PVDate]. If these controls have different values then this only helps if I know how [EndDate] is determined. I can only ignore [EndDate] for now and assume that [PVDate] has the value I require.
Expand|Select|Wrap|Line Numbers
  1. SELECT [MEQA],
  2.        Format(tH.Month,'mmmm yyyy') AS [Month]
  3. FROM tblHistory AS tH
  4. WHERE tH.Month Between CDate('1 ' & Format(DateAdd("m",-12,Forms!frmStats.PVDate),'mmmm yyyy'))
  5.                    And DateAdd("d",-1,CDate('1 ' & Format(DateAdd("m",1,Forms!frmStats.PVDate),'mmmm yyyy')))
  6. ORDER BY tH.Month DESC
The code may be considerably simpler if we know that the dates stored (as [Month]) are always stored as the first day of the month. As I don't know that I have to allow for the worst case scenario (hence the WHERE clause is so complex).
Mar 28 '08 #31
Rickster66
106 100+
WOW!!!!!!! It works!!!
Mar 29 '08 #32
Rickster66
106 100+
What do you think of saving the query as a report to then use it as a sub report?

by the way - A million thanks - the query works well!!!

Richard
Mar 29 '08 #33
NeoPa
32,556 Expert Mod 16PB
Firstly, you're welcome.

As to your question, I'm afraid there seems to be some confusion. As asked it doesn't make any sense. You cannot save queries as reports.

I suspect you have something more straightforward in mind, but I'm afraid I can't guess what that may be. If you can ask the question more clearly I'll happily give my thoughts on the matter.
Mar 31 '08 #34
NeoPa
32,556 Expert Mod 16PB
WOW!!!!!!! It works!!!
I will talk with the other admins about making it a sackable offense to express any surprise when my solutions work in future.

It's as if no-one has any confidence in me :(

(LOL)
Mar 31 '08 #35
Rickster66
106 100+
I will talk with the other admins about making it a sackable offense to express any surprise when my solutions work in future.

It's as if no-one has any confidence in me :(

(LOL)
I always had total and complete faith in you -I was very excited that It is working. I am trying to figure out a way to put the results of the query as a subreport. :)
Mar 31 '08 #36
NeoPa
32,556 Expert Mod 16PB
Of course.

And I'm sure you know I was just kidding around :)
Mar 31 '08 #37
Rickster66
106 100+
Of course.

And I'm sure you know I was just kidding around :)
I presumed that

I have another question, if i need to list every month that does not have a value or is not on the data but must include a value of 0 for that month, how would I go about it?
Mar 31 '08 #38
NeoPa
32,556 Expert Mod 16PB
This is not very straightforward in SQL :(

Essentially what you need to do is have a record source (Let's call it tblDates for this illustration) which would be treated as the master table and must contain all the dates you need to show, then link it to your other data with a LEFT JOIN.

There are two main difficulties with this approach :
  1. The linked fields must be identical, so the [Month] field in your [tblHistory] table MUST be consistent and predictable (easiest is to ensure always the first day of the month).
  2. Providing a record source that has all the dates you need for whatever frmStata.PVDate is, is a very complicated issue.
Apr 1 '08 #39
NeoPa
32,556 Expert Mod 16PB
Let's start with confirming that the [Month] value and the [PVDate] value ALWAYS reflect the first day of the month.

I'm going one step at a time as there is no danger of skipping important steps or questions that way.
Apr 1 '08 #40
Rickster66
106 100+
Let's start with confirming that the [Month] value and the [PVDate] value ALWAYS reflect the first day of the month.
This is no problem. I receive the data dumps in excel and they leave it to me to prepare the data as I see fit so the Month value and the PVDate will ALWAYS be the same. I pick the columns that are needed for this project and incorporate them into the table. What they care about is months so I will make sure both values are the same.
Apr 1 '08 #41
Rickster66
106 100+
This is not very straightforward in SQL :(

Essentially what you need to do is have a record source (Let's call it tblDates for this illustration) which would be treated as the master table and must contain all the dates you need to show, then link it to your other data with a LEFT JOIN.

There are two main difficulties with this approach :
  1. The linked fields must be identical, so the [Month] field in your [tblHistory] table MUST be consistent and predictable (easiest is to ensure always the first day of the month).
  2. Providing a record source that has all the dates you need for whatever frmStata.PVDate is, is a very complicated issue.
I kinda figured that it would be no easy task. The tblDates table would have a PK, and a field with Dates in month format, correct? does that mean that every row of individual dates need to be converted to the 1st dat of the Month - that is VERY POSSIBLE- my bosses only care about Months not specific dates...
Apr 1 '08 #42
NeoPa
32,556 Expert Mod 16PB
This is no problem. I receive the data dumps in excel and they leave it to me to prepare the data as I see fit so the Month value and the PVDate will ALWAYS be the same. I pick the columns that are needed for this project and incorporate them into the table. What they care about is months so I will make sure both values are the same.
As long as you can ensure that all dates are stored as the first of the month (As Access stores month dates anyway) then we're good.

Next we need to create a table called [tblDate] as follows :
Expand|Select|Wrap|Line Numbers
  1. Table Name=[tblDate]
  2. Field; Type; IndexInfo
  3. DateOffset; Numeric; PK
This table needs to be populated with [DateOffset] values of 0 through -12 (13 records).

This may seem a little weird, but it will become clearer when we use it.
Apr 1 '08 #43
NeoPa
32,556 Expert Mod 16PB
...The tblDates table would have a PK, and a field with Dates in month format, correct?...
No. As per my previous post (#43) the data is simply a DateOffset value which is itself the PK.
...Does that mean that every row of individual dates need to be converted to the 1st dat of the Month - that is VERY POSSIBLE- my bosses only care about Months not specific dates...
If you have any date values stored in your [Month] field that are NOT the first of the month then yes.

FYI: If you run this code you will get the result shown :
Expand|Select|Wrap|Line Numbers
  1. MsgBox Format(CDate("November 2008"),"d mmmm yyyy")
  2. 1 November 2008
This is the default date Access assumes if you leave out the day number and just use the month.
Apr 1 '08 #44
NeoPa
32,556 Expert Mod 16PB
The last step is to change the SQL of your query to :
Expand|Select|Wrap|Line Numbers
  1. SELECT tH.MEQA,
  2.        Format(subD.Month,'mmmm yyyy') AS [Month]
  3. FROM (SELECT DateAdd('m',[DateOffset],Forms!frmStats.PVDate) AS Month
  4.       FROM tblDate) AS subD LEFT JOIN
  5.      tblHistory AS tH
  6.   ON subD.Month=tH.Month
  7. ORDER BY subD.Month DESC
Apr 1 '08 #45
Rickster66
106 100+
The last step is to change the SQL of your query to :
Expand|Select|Wrap|Line Numbers
  1. SELECT tH.MEQA,
  2.        Format(subD.Month,'mmmm yyyy') AS [Month]
  3. FROM (SELECT DateAdd('m',[DateOffset],Forms!frmStats.PVDate) AS Month
  4.       FROM tblDate) AS subD LEFT JOIN
  5.      tblHistory AS tH
  6.   ON subD.Month=tH.Month
  7. ORDER BY subD.Month DESC
I am not getting any values on the MEQA field
Apr 1 '08 #46
NeoPa
32,556 Expert Mod 16PB
Post in what all your settings are (the value of the PVDate control; The actual results of the query etc) and we'll see what might be missing.

PS. Include the data of the relevant records in tblHistory too, showing all dates completely.
Apr 1 '08 #47
Rickster66
106 100+
Post in what all your settings are (the value of the PVDate control; The actual results of the query etc) and we'll see what might be missing.

PS. Include the data of the relevant records in tblHistory too, showing all dates completely.

for PVDate I have entered 2/28/2008,2/1/2008, and february 2008 with nothing showing in the MEQA column - these are results:

Expand|Select|Wrap|Line Numbers
  1.                 MEQA    Month
  2.  
  3.                  February 2009
  4.                  January 2009
  5.                  December 2008
  6.                             November 2008
  7.                 October 2008
  8.                 September 2008
  9.                 August 2008
  10.                 July 2008
  11.                June 2008
  12.                 May 2008
  13.                April 2008
  14.                March 2008
  15.                            February 2008
Here are the records from tbl history:

Expand|Select|Wrap|Line Numbers
  1.  
  2. DateReceived    Month    Initials    MEQA
  3.  
  4. 1/6/2007    January 2007    DKS    13
  5. 1/9/2007    January 2007    KKD    7
  6. 1/9/2007    January 2007    YRM    4
  7. 1/10/2007    January 2007    CNH    6
  8. 1/12/2007    January 2007    RBD    1
  9. 1/16/2007    January 2007    HKT    6
  10. 2/16/2007    February 2007    JPT    7
  11. 3/18/2007    March 2007    YRM    14
  12. 3/18/2007    March 2007    RRS    4
  13. 4/19/2007    March 2007    KKD    13
  14. 4/23/2007    March 2007    KEL    1
  15.  
  16. etc
  17.  
i hope this information is clear

thanks again,

Richard
Apr 1 '08 #48
NeoPa
32,556 Expert Mod 16PB
Richard, this indicates to me that you haven't followed the instructions in post #43 quite correctly.

The numbers should be 0 through (minus)12.

To fix this without redoing the table data, just add a - (minus) before the [DateOffset] bit in line #3 of the latest SQL code.
Expand|Select|Wrap|Line Numbers
  1. FROM (SELECT DateAdd('m',-[DateOffset],Forms!frmStats.PVDate) AS Month
Let me know how it goes after that.
Apr 1 '08 #49
Rickster66
106 100+
Richard, this indicates to me that you haven't followed the instructions in post #43 quite correctly.

The numbers should be 0 through (minus)12.

To fix this without redoing the table data, just add a - (minus) before the [DateOffset] bit in line #3 of the latest SQL code.
Expand|Select|Wrap|Line Numbers
  1. FROM (SELECT DateAdd('m',-[DateOffset],Forms!frmStats.PVDate) AS Month
Let me know how it goes after that.
Good Morning, Here's what I get when I enter 2/1/2008:

Expand|Select|Wrap|Line Numbers
  1.  
  2. MEQA    Month
  3.     February 2008
  4.     January 2008
  5.     December 2007
  6.     November 2007
  7.     October 2007
  8.     September 2007
  9.     August 2007
  10.     July 2007
  11.     June 2007
  12.     May 2007
  13.     April 2007
  14.     March 2007
  15.     February 2007
  16.  
The MEQA field still shows nothing. Would it be feasible to perhaps use this newly created query and join it with tbl History again? I'll give it a shot--
Apr 2 '08 #50

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

Similar topics

132
by: Kevin | last post by:
I don't know if I should even start this topic but here goes. I'm an ex vb6 developer, now developing in C#. The reason why I started developing in C# is because the company that I worked for at...
9
by: Bazza Formez | last post by:
Hi there, For some reason, when I edit row in my datagrid, some columns have (an unwanted) back color of yellow, while others correctly display with white back color. I can see no setting in...
2
by: Terry Olsen | last post by:
I've got my datgrid loaded (finally). I can select rows & delete them. But I can't select columns to delete them. When I click on a column header, all that happens is the grid is resorted by that...
2
by: monomaniac21 | last post by:
hi all im trying to write a pdf document which contains two columns of data. when the column on the left crosses over to the next page i need to be able to go back afterwards to the previous...
0
by: hime | last post by:
Hello I have a data entry web App. form. the login page for this form depends on checking whether the user name and password exists in the data base or not only; which means that I didn't use...
4
by: toglez | last post by:
Hi all! I use PyQt4 and Python to create a program to display numbers from a file in a QTable Widget, select various columns from the table and then display the selected columns in a new table. ...
28
by: Rickster66 | last post by:
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...
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...
3
by: adarshyam | last post by:
friends, i have a problem in going back to previous page in my application.. since i want that to happen in the if else statement i cannot incorporate JS. please help me .. i am trying this...
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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,...

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.