PZPZ
Oct 30 2007, 08:56 AM
I have two Queries: Query A and Query B
Right now I have a report that pulls data on individuals from Query A only.
However, there is one individual from Query B I need to also add to the report. Is there an easy way to do this by just using relationships? I thought about somehow adding Query B as a relationship to Query A and then just basing the report on Query A......but I don't see how this is going to work because the report might pull all individuals from Query B, when I only want it to pull one individual.
Doug Steele
Oct 30 2007, 09:00 AM
Create a third query that joins Query A to Query B, and use that third query.
PZPZ
Oct 30 2007, 09:06 AM
Okay, I am trying this....but the thing is that the one Individual I need from Query B is not represented in Query A...
So there are like 25 fields in each query but this individual's information is all in Query B and none of it is in Query A.
Will an append query work?
Caffiend
Oct 30 2007, 09:13 AM
Are queryA and B based on the sames tables? Maybe it's possible to combine your 2 queries into a single query and use it as the source for the report.
If you don't think there is any chance to combine the queries then I would suggest you use a union query.
PZPZ
Oct 30 2007, 09:23 AM
Query A and Query B are each based off of different items....actually Query A is based off a table and Query B is based off of a Form.
Is a Union query the same as an append query....if not....is this available in Access 2000?
Is there code I can use where I can add a check box on a Form so that if someone enters let's say Individual A's information on the form, and they click the check box....the information will also be entered in another query or table?
Thank you.
Caffiend
Oct 30 2007, 09:34 AM
QUOTE
Is a Union query the same as an append query....if not....is this available in Access 2000?
No, completely different. An append query adds records to a table and you cannot base a report on it. A union query has to be coded in SQL because the query builder does not support it (but it is availble in Access 2000). The syntax is like this:
CODE
select person, col1, col2, col3 from QueryA
UNION
select person, col1, col2, col3 from QueryB
PZPZ
Oct 30 2007, 10:09 AM
Okay I really do not know how to use SQL but am trying what you said....
The thing is that is this something I am going to have to repeat everytime another individual is added to query B?
And what if there are not equal numbers of columns in both queries or equal numbers of columns not being pulled from both queries.....
Also....is it worth getting really good at Visual Basic or just focusing on SQL if most of my work is in Access?
Here is the code that already exists in SQL for query A (see below). So I need to add something similar for query B on top of the Select statement below to do the union query?
SELECT [VAD Form].PatID, [VAD Form].Organ, [VAD Form].[MR#], [VAD Form].SSN, [Last Name] & ", " & [First Name] AS Name, [VAD Form].[Last Name], [VAD Form].[First Name], [VAD Form].[Bld Grp], [VAD Form].Ht, [VAD Form].Htft, [VAD Form].Htinch, [VAD Form].Wt, (([Htft]*12)+([Htinch]))*0.0254 AS Htm, [Wt]/2.2 AS Wtkg, ([Wtkg])/([Htm]*[Htm]) AS BMI, [VAD Form].[VAD pts], [LVAD] & " " & [LVAD Implant Date] AS LVADData, [VAD Form].LVAD, [VAD Form].[LVAD Implant Date], [RVAD] & " " & [RVAD Implant Date] AS RVADData, [VAD Form].RVAD, [VAD Form].[RVAD Implant Date], [VAD Form].[VAD 1A time taken], [VAD Form].[VAD 1A days], [VAD Form].[In hosp], [VAD Form].[New Comments], [Current Status].[Status Start Date] AS [Current Status Date], IIf(IsNull([Reason for removal]),[Current Status]![Status]) AS [Current Status], [VAD Form].Status, [VAD Form].[Status Date], [VAD Form].[Listing Date], [VAD Form].Crossmatch, [VAD Form].Treated1, [VAD Form].Treated2, [VAD Form].Treated3, [PK POS] & " " & [PK Date] AS PKPRA, [VAD Form].[PK POS], [VAD Form].[PK Date], [VAD Form].PK_ClassI, [VAD Form].PK_ClassII, [CURR POS] & " " & [CURR Date] AS CURRPRA, [VAD Form].[CURR POS], [VAD Form].[CURR Date], [VAD Form].CURR_ClassI, [VAD Form].CURR_ClassII, [VAD Form].Antibodies, [VAD Form].[Current Condition], [VAD Form].[Plan @ Tx], [List interval_Crosstab].[1A], [List interval_Crosstab].[1B], IIf(Not (IsNull([List interval_Crosstab]![1A])),([List interval_Crosstab]![1A]+[List interval_Crosstab]![1B]),[List interval_Crosstab]![1B]) AS 1btotal, [List interval_Crosstab].[2], [List interval_Crosstab].[7], IIf(Not (IsNull([List interval_Crosstab]![7])),(Now()-[Listing Date]-[List interval_Crosstab]![7]),(Now()-[Listing Date])) AS Total, [VAD Form].[HIT Status], [VAD Form].HITDate1, [VAD Form].HIT1, [VAD Form].HITDate2, [VAD Form].HIT2, [VAD Form].HITDate3, [VAD Form].HIT3, [VAD Form].HITRemarks, [VAD Form].RHC, [VAD Form].[RHC remarks], [VAD Form].[Worst RA], [VAD Form].[Worst PAS/M/D], [VAD Form].[Worst PCW/PVR], [VAD Form].[Worst CO], [VAD Form].[Best RHC Date], [VAD Form].[Best RHC remarks], [VAD Form].[Best RA], [VAD Form].[Best PAS/M/D], [VAD Form].[Best PCW/PVR], [VAD Form].[Best CO], [VAD Form].[Next RHC]
Caffiend
Oct 30 2007, 11:51 AM
QUOTE
Okay I really do not know how to use SQL but am trying what you said....
the best advice I can give you here is to start small just start with a single field and build up from there.
QUOTE
The thing is that is this something I am going to have to repeat everytime another individual is added to query B?
No not at all queries are dynamic and as your data changes the data returned will change as well. It does not matter if B returns one row or one thousand
QUOTE
And what if there are not equal numbers of columns in both queries or equal numbers of columns not being pulled from both queries.....
You just need to account for these fields that exist in one query and not the other. See my example below where I have fields that are in QueryA that are not in QueryB and vice versa...
CODE
select first_name & " " & last_name, col1, col2, col3, 0 as col4, col5 from QueryA
UNION
select fullName, col1, col2, col3, col4, "" as col5 from QueryB
QUOTE
Also....is it worth getting really good at Visual Basic or just focusing on SQL if most of my work is in Access?
VB skills always come in handy when working with Access, but don't really on it too much... use the right tool for the job.
QUOTE
Here is the code that already exists in SQL for query A (see below). So I need to add something similar for query B on top of the Select statement below to do the union query?
I am suggesting that your UNION query be a third query, sorry if this was not clear. So you don't nessesarily have to add queryB's sql into queryA... combining multiple queries into one is the ideal in my opinion, but it's probably more advanced than you need at this point.
PZPZ
Oct 30 2007, 12:05 PM
Why do I get this message ( "Query Input Must Contain atleast One Table or Query") when I am trying to do a Union query and I am using queries already?
Caffiend
Oct 30 2007, 12:34 PM
can you post the SQL you're using?