I am new to Stack Overflow and to ASP, but this site has bailed me out many times! I am very unfamiliar with ASP and VBS but more familiar with PHP, so if there is a PHP solution to my problem, that will be okay too.
A little background - My access DB has two tables (that are relevant to this query) one is called SignUpLog
and the other Notes
. The SignUpLog.FirstNoteAddr
field corresponds to the Notes.NoteKey
field in the other table.
I've been successful in showing all the entries in the DB, but what I'd like to do is group all entries for a specific patient together in one row, while still ordering by date (newest at top).
Here's my code:
Set DataConn = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.RecordSet")
DataConn.Open "DBQ=" & Server.Mappath("/path/to/mydb") & ";Driver={Microsoft Access Driver (*.mdb)};Uid=user;Pwd=pass;"
Set rsDsp = DataConn.Execute("SELECT SignUpLog.PatientFileNumber, SignUpLog.ArrivalDateTime, Notes.Note, SignUpLog.Called, SignUpLog.DrName FROM SignUpLog, Notes WHERE (((Notes.NoteKey)=[SignUpLog].[FirstNoteAddr])) ORDER BY SignUpLog.ArrivalDateTime DESC;")
If rsDsp.EOF Then
Response.Write "Sorry, no entries in the database!"
Else
%>
<div align="center"><center>
<table BORDER="0" width="700">
<tr>
<th width="105">Name</th>
<th width="105">Arrival Time</th>
<th width="105">Doctor</th>
<th width="105">Notes</th>
</tr>
<%
While Not rsDsp.EOF
x = x + 1
If x = 1 Then
Response.Write "<TR><TD>" & rsDsp.Fields.Item("PatientFileNumber").Value & "</TD>"
Response.Write "<TD>" & rsDsp("ArrivalDateTime").Value & "</TD>"
Response.Write "<TD>" & rsDsp("DrName").Value & "</TD>"
Response.Write "<TD>" & rsDsp("Note").Value & "</TD></TR>"
Else
Response.Write "<TR><TD BGCOLOR=E4E4E4>" & rsDsp.Fields.Item("PatientFileNumber").Value & "</TD>"
Response.Write "<TD BGCOLOR=E4E4E4>" & rsDsp("ArrivalDateTime").Value & "</TD>"
Response.Write "<TD BGCOLOR=E4E4E4>" & rsDsp("DrName").Value & "</TD>"
Response.Write "<TD BGCOLOR=E4E4E4>" & rsDsp("Note").Value & "</TD></TR>"
x = 0
End If
rsDsp.MoveNext
Wend
Response.Write "</TABLE>"
DataConn.Close
End If
%>
</table>
</center></div>
This gives me an output similar to this:
Patient A | 9/18/2012 12:56:21 PM | Appt | Note1
Patient A | 9/18/2012 12:56:21 PM | Appt | Note2
Patient A | 9/18/2012 12:56:21 PM | Appt | Note3
Patient B | 9/18/2012 1:56:21 PM | WalkIn | Note1
Patient B | 9/18/2012 1:56:21 PM | WalkIn | Note2
What i would like is this :
Patient A | 9/18/2012 12:56:21 PM | Appt | Note1, Note2, Note3
Patient B | 9/18/2012 1:56:21 PM | WalkIn | Note1, Note2
I've tried playing around with Group By
and keep getting hung up on Aggregate functions, which is confusing because I'm not trying to do anything mathematical. Like said I am a complete ASP noob, and I'm not a programmer by no means.