1

私は 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 初心者であり、決してプログラマーではありません。

4

3 に答える 3

0

HTML で深刻な失敗。

とにかく、結果セットをループして表示するためのロジックにいくつかの変更を加えることによる簡単な解決策があります。

<%
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">
    <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> 
 <%
   Dim LastPatient;
   Dim Notes = "";
   Dim x = 0;
   While Not rsDsp.EOF

     If LastPatient = rsDsp.Field.Item("PatientFileNumber").Value Then
       Response.Write "<br />" & rsDsp("Note").Value
     Else
       If LastPatient <> NULL Then
         Response.Write "</td></tr>"
       If x Mod 2 = 0 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
       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
       End If
       x = x + 1
     End If

     LastPatient = rsDsp.Fields.Item("PatientFileNumber").Value
     rsDsp.MoveNext 
   Wend
   Response.Write "</td></tr>"   


   DataConn.Close 

End If
%> 
 </table> 
</div>
于 2012-09-20T14:54:36.637 に答える
0

ここであなたの問題の解決策がすでにあると思います。この質問を見てみてください。(少し複雑な)関数を定義して、例のように使用するだけです。

于 2012-09-18T18:21:08.383 に答える
0

これは実際には、ASP とはほとんど関係のない SQL クエリの問題です。MDB を使用しているため、MS Access を使用してクエリをモデル化し、生成された SQL ステートメントを ASP コードに貼り付ける方が簡単な場合があります。

次の質問が役に立ちます。

並べ替え付きの SQL グループ

于 2012-09-18T18:21:42.920 に答える