Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Query problem

Status
Not open for further replies.

MadCatmk2

Programmer
Oct 3, 2003
145
GB
Hi all

I have a question regarding combining two queries into one that will do the same job.

I have created two access 97 queries:

The first (temp contacts) is designed to query a table [Contacts] for all fields where the patient number = a certain value

Code:
SELECT CONTACTS.*, CONTACTS.PATIENT_NO
FROM CONTACTS
WHERE (((CONTACTS.PATIENT_NO)="tw885" Or (CONTACTS.PATIENT_NO)="ws440"))

this works no problem.
The second query checks certain fields within the data returned from (temp contacts) and looks for duplication. It returns the fields that fit the criteria.

Code:
SELECT DISTINCTROW [temp contacts].CONTACTS.PATIENT_NO, [temp contacts].DATE_OF_VISIT, [temp contacts].TIME_OF_VISIT, [temp contacts].CARE_PACKAGE, [temp contacts].STAFF_NO, [temp contacts].DISCIPLINE, [temp contacts].INTERVENTIONS, [temp contacts].LOCATION
FROM [temp contacts]
WHERE ((([temp contacts].DATE_OF_VISIT) In (SELECT [DATE_OF_VISIT] FROM [temp contacts] As Tmp GROUP BY [DATE_OF_VISIT],[TIME_OF_VISIT],[CARE_PACKAGE],[STAFF_NO],[DISCIPLINE],[INTERVENTIONS],[LOCATION] HAVING Count(*)>1  And [TIME_OF_VISIT] = [temp contacts].[TIME_OF_VISIT] And [CARE_PACKAGE] = [temp contacts].[CARE_PACKAGE] And [STAFF_NO] = [temp contacts].[STAFF_NO] And [DISCIPLINE] = [temp contacts].[DISCIPLINE] And [INTERVENTIONS] = [temp contacts].[INTERVENTIONS] And [LOCATION] = [temp contacts].[LOCATION])))
ORDER BY [temp contacts].DATE_OF_VISIT, [temp contacts].TIME_OF_VISIT, [temp contacts].CARE_PACKAGE, [temp contacts].STAFF_NO, [temp contacts].DISCIPLINE, [temp contacts].INTERVENTIONS, [temp contacts].LOCATION;

This also works.

The problem i have is that i want to return the values of the duplicateQuery as a recorset in VB.

Is it possible to combine the two queries into one so that i can do this.

I'm really struggling to figure it out.

All help is appreciated.
Thanks in advance
 
correction. Sorry, i still have not been able to combine the queries.

Any help would be useful at this stage.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top