私は Stack Overflow と ASP は初めてですが、このサイトには何度もお世話になりました。私は ASP と VBS にはあまり詳しくありませんが、PHP には詳しいので、私の問題に対する PHP ソリューションがあれば、それも問題ありません。
ちょっとした背景 - 私のアクセス DB には 2 つのテーブル (このクエリに関連するもの) があり、1 つは呼び出されSignUpLog
、もう1 つはNotes
. フィールドは、他のテーブルのフィールドにSignUpLog.FirstNoteAddr
対応します。Notes.NoteKey
DB 内のすべてのエントリを表示することに成功しましたが、特定の患者のすべてのエントリを 1 行にグループ化し、日付順 (最新) に並べたいと考えています。
これが私のコードです:
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>
これにより、次のような出力が得られます。
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
私が欲しいのはこれです:
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
私はGroup By
集計関数をいじってみましたが、数学的なことをしようとしていないので混乱しています。言ったように、私は完全な ASP 初心者であり、決してプログラマーではありません。