I created a small data base based on your sample data and my interpretation.
Tables were design I suggested.
tblPatientX
patientID |
patientName |
1 |
A |
2 |
B |
Some made up data for table
jnctblPatientEvent
PatientID |
EventId |
EventDate |
1 |
1 |
29/12/2014 |
1 |
2 |
31/12/2014 |
1 |
3 |
12/11/2014 |
1 |
4 |
07/10/2014 |
2 |
3 |
12/11/2014 |
2 |
5 |
08/01/2015 |
2 |
6 |
20/10/2014 |
tblEventX
EventID |
EventName |
1 |
Vomiting |
2 |
Asthma |
3 |
Fever |
4 |
Cough |
5 |
Viral |
6 |
Nausea |
This query (starting point)
Code:
SELECT tblPatientX.patientName, concatRelated('EventID','jnctblPatientEvent','PatientID = ' & [PatientID] ) as Events
FROM tblPatientX
to get this result (I haven't attempted to get the names of events)
Code:
patientName |
Events |
A |
1 , 2 , 3 , 4 |
B |
5 , 6 , 3 |
UPDATE: Another look and was able to put the EventId and Names together in concatenated format.
I used a query to put the eventId and EventName together in query 'EventsWithNames'
Code:
SELECT jnctblPatientEvent.PatientID, [jnctblPatientEvent].[EventId] & " " & [tblEventX].[EventName] AS EventIdAndName
FROM tblEventX INNER JOIN jnctblPatientEvent ON tblEventX.EventID = jnctblPatientEvent.EventId;
which gives this format
Code:
PatientID |
EventIdAndName |
1 |
1 Vomiting |
1 |
2 Asthma |
1 |
3 Fever |
2 |
3 Fever |
1 |
4 Cough |
2 |
5 Viral |
2 |
6 Nausea |
and then modified the final concatenation using this query
Code:
SELECT tblPatientX.patientName, concatRelated(' EventIDandName','EventsWithNames','PatientID = ' & [PatientID] ) as Events
FROM tblPatientX
which produces the format you requested
Code:
patientName |
Events |
A |
1 Vomiting , 2 Asthma , 3 Fever , 4 Cough |
B |
3 Fever , 5 Viral , 6 Nausea |
Hope this is useful.
Good luck