473,488 Members | 2,464 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

query help for a report in access 2003

19 New Member
ok I ma having a problem trying to filter out extra data from a table to generate a report
the table has a list of drawings and a particular project number associated with it so I created a report based on this query select * from tblwiringdiagram where project number = [Please enter Value]

now this works great.

then i get an Oh BTW we only need to show the latestest revisions of a particular drawing that is part of a project

so iam having a problem trying to add that extra piece to the report
the select statement i was thinking about was select * from tblwiringdiagram where revision=max(revision) but I dont know how to make it go for each individual drawing since the revsions for the drawings will be different

i am using Access 2003 if that helps any

thanks in advance for your help

CG
Apr 12 '07 #1
8 1712
MMcCarthy
14,534 Recognized Expert Moderator MVP
You can't Select * and have Max(Revision). What is the metadata of the table tblwiringdiagram and what fields do you absolutely have to return from that query.

Here is an example of how to post table MetaData :
Table Name=tblBookings
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. Field; Type; IndexInfo
  3. StudentID; Autonumber; PK
  4. Family; String; FK
  5. Name; String
  6. University; String; FK
  7. Mark; Numeric
  8. LastAttendance; Date/Time
Mary
Apr 13 '07 #2
cgrider
19 New Member
here is the metadata for the table
tablename=tblwiringdiagram
Expand|Select|Wrap|Line Numbers
  1. project_number,string
  2. Serial_number, numeric
  3. Drawing_number,string
  4. Wire_number,string
  5. From_Conn,string
  6. From_term,string
  7. To_conn,string
  8. To_term,string
  9. revision,string
  10.  
the report has all of the fields from the table on it

originally the select statement for the report was
select * from tblwiringdiagram since the revision did not come into play
but now the revision is a factor and I am pretty clueless on how to create the sql statement for this

what is needed on the report is a list of all the drawings and their connectors from a particular project but only show the latest revision of that said drawing

the revision is in the form of A,B,C...etc so I was going to use the max of it to only select the latest.

I hope this helps
Apr 13 '07 #3
MMcCarthy
14,534 Recognized Expert Moderator MVP
First problem is Revision is a string so what is the value in there.
Apr 13 '07 #4
cgrider
19 New Member
the revision field is of one Char revision A, revision B etc so it is just stripped down to the individual char A, B, etc

here is the sql command I just came up with let me know if this looks correct and/or is there anythign in there that is not needed.

Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM tblwiringdiagram AS db1 RIGHT JOIN [SELECT tblWiringDiagram.Drawing_Number, Max(tblWiringDiagram.Revision) AS MaxOfRevision
  3. FROM tblWiringDiagram
  4. GROUP BY tblWiringDiagram.Drawing_Number]. AS db2 ON (db1.Drawing_Number = db2.Drawing_Number) AND (db1.Revision = db2.MaxOfRevision)
  5. WHERE (((db1.Project_number)=[Please Enter the Project Number]));
  6.  
  7.  
Apr 13 '07 #5
MMcCarthy
14,534 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM tblwiringdiagram AS db1 RIGHT JOIN (SELECT tblWiringDiagram.Drawing_Number, Max(tblWiringDiagram.Revision) AS MaxOfRevision
  3. FROM tblWiringDiagram
  4. GROUP BY tblWiringDiagram.Drawing_Number) AS db2 
  5. ON (db1.Drawing_Number = db2.Drawing_Number 
  6. AND db1.Revision = db2.MaxOfRevision)
  7. WHERE (((db1.Project_number)=[Please Enter the Project Number]));
  8.  
I don't think the Max will work properly on the text field but you can try it. I made a couple of changes to the syntax. Just wondering why you are using a right join rather than an inner join.
Apr 13 '07 #6
cgrider
19 New Member
it looks like it does work so far so keeping fingers corssed :) thanks for you help as for the right as opposed to the inner I changed it to the latter and the query worked also with no change in number of records so I guess either works. is one better than the other for speed wise? I am not that familiar with either approach so any input would be appreciated. As for the Max() working with string I believe it converts it to the ascii representation of the text and does it calculations based off that. So a lower case A would be greater than an uppercase A. I am only guessing, if someone could verify that I would greatly appreciate it. If this is the case I will have to add the function ToUpper() for the string to make sure noone put a lower case in there to mess with the revision.

Thank you for all your help

CG
Apr 13 '07 #7
MMcCarthy
14,534 Recognized Expert Moderator MVP
it looks like it does work so far so keeping fingers corssed :) thanks for you help as for the right as opposed to the inner I changed it to the latter and the query worked also with no change in number of records so I guess either works. is one better than the other for speed wise? I am not that familiar with either approach so any input would be appreciated.
The right join pulls all records from the recordset on the right and only matching records from the left recordset. Left join does the reverse. In this case you only want records that match in both tables so an inner join is appropriate.
As for the Max() working with string I believe it converts it to the ascii representation of the text and does it calculations based off that. So a lower case A would be greater than an uppercase A. I am only guessing, if someone could verify that I would greatly appreciate it. If this is the case I will have to add the function ToUpper() for the string to make sure noone put a lower case in there to mess with the revision.
I'm not expert on this but I'm pretty sure you are correct on this.
Thank you for all your help

CG
You're welcome
Apr 13 '07 #8
cgrider
19 New Member
well I did some testing wiuth upper and lower cases it did not seem to care. An "A" was the same as an "a" so I am not sure how it does its calculations. So if anyone has any insight on this i would appreciate it.

thanks

CG
but the code is working so all is good for the time being :)
Apr 13 '07 #9

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

Similar topics

6
4493
by: Mahesh Hardikar | last post by:
Hi , Oracle 8.1.7.0.0 on HP-UX 11.0 I am a newbie as far as PL-SQL is concerned . I have Sybase/MSSQL T-SQL background. We have a report which uses a select statement . This select...
5
3116
by: Ken Lindner | last post by:
We have a report based on a query that is called from a form. Nothing too special here. The query has 3 coulmns that are populated directly from values entered into entry fields on the form...
1
2897
by: longtim | last post by:
I have been having endless difficulty creating reports/queries that set any relevent parameters from controls in forms. I am creating an application under access 2003 but will target access...
5
1650
by: Andy Davis | last post by:
I have a two tables, Users and Requests, the latter which displays the daily log on's of 20 users. Both tables are related by a one-to-many relationship in the Requests table via the UserId field....
3
5586
by: Ray Holtz | last post by:
Access 2003 (2000 file format) question: When I run a form, it opens with only a combo box and a button to execute a query based on the criteria tha is selected in the combobox. Then I need...
3
2178
by: Wired Hosting News | last post by:
Lets say I have 10 products in 10 different stores and every week I get a report from each store telling me how many items they have left for each of the 10 products. So each week I enter in 100...
5
3496
by: Wired Hosting News | last post by:
I tried to be breif and give a scenario so as not to be overlooked because it was soooo long. Let me give you real world. I am a manufacturer of goods and produce 11 items that are distributed...
2
1507
by: starke1120 | last post by:
I have a query that has a prompt for date as Between And This database is hosted on a share drive. About half of my user's are ok with the report that has this query the other half when the...
22
31144
by: Stan | last post by:
I am working with Access 2003 on a computer running XP. I am new at using Access. I have a Db with a date field stored as mm/dd/yyyy. I need a Query that will prompt for the month, ie. 6 for...
32
2646
by: wexx | last post by:
I have been looking for some time now (reading books off Safari, searching through forums,etc) I have found no solution to this problem. I turn to anyone of you that may be able to help me. I'm...
0
6967
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
7142
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,...
1
6847
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
7352
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4875
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.