asp报告中的SQL Server

时间:2016-04-01 15:17:34

标签: sql-server asp-classic

我遇到了一个问题,我需要完成一些事情,但之前从未有过这方面的经验。我目前正在运行一个asp站点并使用SQL Server作为数据库。我有一个报告,我从过滤器页面获取查询,然后根据querstring提供信息。这是一个入学报告,因此报告中只应出现一个行项目和每个客户帽的记录。在报告中,它提供了诸如首次联系日期以及客户何时与我们开始服务等信息。我在报告中添加了一个名为services的新字段。向一个客户端提供许多服务是可能的,也是更常见的。这是我需要完成的。我需要将该客户端的每个服务列在报表的单个数据单元格中,而不显示该客户端的多个订单项。我当时认为可以通过使用BOF和EOF来完成答案,但我不确定如何对它进行攻击。这是已经在报表上的RecordSet,它包含除新字段之外的每个字段,因为我试图为该字段创建一个新的RecordSet。下面的图片将有希望给出我想要完成的想法。非常感谢您的投入!

这个图像就像现在的样子......我想把aa aa所显示的所有服务放在一个数据单元中,而不是为每个提供的服务创建一个新行。 Image of what It looks like now.

这是我在photoshop中创建的图像,用于显示我真正想要的样子。 This is a rough idea of What I want it to look like.

到目前为止,这是代码。

<%
Dim rsClients
Dim rsClients_numRows

Set rsClients = Server.CreateObject("ADODB.Recordset")
rsClients.ActiveConnection = MM_ims_db_STRING
rsClients.Source = "SELECT" _
& " vClients.ClientID" _
& ", vClients.AgencyID" _
& ", vClients.OfficeID" _
& ", vClients.OfficeName" _
& ", vClients.LastName" _
& ", vClients.FirstName" _
& ", vClients.ClientTeamName" _
& ", vClients.EnrolledDate" _
& ", vClients.Agency" _
& ", ReferralSources.ReferralSourceID" _
& ", ReferralSourceText" _
& ", ReferralTypeID" _
& ", ReferralSources.ReferralSource" _
& ", ReferralType" _
& ", vClients.DataEntryDate" _
& ", vClients.DataEntryDays" _
& ", ReferralStaffID" _
& ", ReferralStaffName" _
& ", DataEntryStaffID" _
& ", Staff_1.FirstName + ' ' + Staff_1.LastName AS DataEntryStaffName" _
& ", vClients.Intake1stContactStaffID" _
& ", Staff.FirstName + ' ' + Staff.LastName AS Intake1stContactStaffName" _
& ", vClients.Intake1stContactAssignedDate" _
& ", vClients.Intake1stContactCompletedDate" _
& ",vClients. Intake1stScheduledStaffID" _
& ", Staff_2.FirstName + ' ' + Staff_2.LastName AS Intake1stScheduledStaffName" _
& ", vClients.Intake1stScheduledAssignedDate" _
& ", vClients.Intake1stScheduledCompletedDate" _
& ", vClients.IntakeAssessorStaffID" _
& ", Staff_3.FirstName + ' ' + Staff_3.LastName AS IntakeAssessorStaffName" _
& ", vClients.IntakeAssessorAssignedDate" _
& ", vClients.IntakeAssessorCompletedDate" _
& ", vClients.IntakeReviewerStaffID" _
& ", Staff_4.FirstName + ' ' + Staff_4.LastName AS IntakeReviewerStaffName" _
& ", vClients.IntakeReviewerAssignedDate" _
& ", vClients.IntakeReviewerCompletedDate" _
& ", vClients.IntakeServicesStaffID" _
& ", Staff_5.FirstName + ' ' + Staff_5.LastName AS IntakeServicesStaffName" _
& ", vClients.IntakeServicesAssignedDate" _
& ", vClients.IntakeServicesCompletedDate" _
& ", vClients.Intake1stContactAssignedDays" _
& ", vClients.Intake1stContactCompletedDays" _
& ", vClients.Intake1stScheduledAssignedDays" _
& ", vClients.Intake1stScheduledCompletedDays" _
& ", vClients.IntakeAssessorAssignedDays" _
& ", vClients.IntakeAssessorCompletedDays" _
& ", vClients.IntakeReviewerAssignedDays" _
& ", vClients.IntakeReviewerCompletedDays" _
& ", vClients.IntakeServicesAssignedDays" _
& ", IntakeServicesCompletedDays" _
& ", Staff_6.FirstName + ' ' + Staff_6.LastName AS Intake1stSessionStaffName" _
& ", vClients.Intake1stSessionDate" _
& ", vClients.Intake1stSessionDays" _
& ", vClientServices.PurposeCodeID" _
& ", vClientServices.PurposeType" _
& ", vClientServices.PurposeCode" _
& ", vClientServices.PurposeDescription" _
& ", vClients.Status" _
& " FROM vClients" _
& " LEFT OUTER JOIN dbo.Staff ON vClients.Intake1stContactStaffID = Staff.StaffID " _
& " LEFT OUTER JOIN dbo.vClientServices ON vClientServices.ClientID = vClients.ClientID " _
& " LEFT OUTER JOIN dbo.ReferralSources ON vClients.ReferralSourceID = ReferralSources.ReferralSourceID" _
& " LEFT OUTER JOIN dbo.Staff AS Staff_1 ON Staff_1.StaffID = vClients.DataEntryStaffID " _
& " LEFT OUTER JOIN dbo.Staff AS Staff_2 ON Staff_2.StaffID = vClients.Intake1stScheduledStaffID" _
& " LEFT OUTER JOIN dbo.Staff AS Staff_3 ON Staff_3.StaffID = vClients.IntakeAssessorStaffID  " _
& " LEFT OUTER JOIN dbo.Staff AS Staff_4 ON Staff_4.StaffID = vClients.IntakeReviewerStaffID  " _
& " LEFT OUTER JOIN dbo.Staff AS Staff_5 ON Staff_5.StaffID = vClients.IntakeServicesStaffID  " _
& " LEFT OUTER JOIN dbo.Staff AS Staff_6 ON Staff_6.StaffID = vClients.Intake1stSessionStaffID  " _
& rsClients__sqlFrom _
& " WHERE " & rsClients__sqlFilter _
& " ORDER BY " & rsClients__sqlSortBy & ""
rsClients.CursorType = 0
rsClients.CursorLocation = 2
rsClients.LockType = 1
rsClients.Open()

rsClients_numRows = 0
%>





 <% If Not rsClients.EOF And Not rsClients.BOF Then %>
          <% 
    While ((Repeat1__numRows <> 0) AND (NOT rsClients.EOF)) 
    %>
            <tr class="gridItem">
              <td align="center" nowrap="nowrap"><a href="/clientsDetails.asp?ClientID=<%=rsClients.Fields.Item("ClientID").Value%>"><img src='/images/details16x16.gif' border='0' title='Client Details' /></a></td>
              <td nowrap="nowrap"><%=rsClients.Fields.Item("FirstName").Value & " " & rsClients.Fields.Item("LastName").Value%></td>
              <td nowrap="nowrap"><%=(rsClients.Fields.Item("Status").Value)%></td>
              <td nowrap="nowrap"><%=(rsClients.Fields.Item("OfficeName").Value)%></td>
              <td nowrap="nowrap"><%=(rsClients.Fields.Item("ClientTeamName").Value)%></td>
              <td nowrap="nowrap"><%=(rsClients.Fields.Item("PurposeType").Value & " - " & rsClients.Fields.Item("PurposeDescription").Value)%></td>
              <td align="center"><%=(rsClients.Fields.Item("EnrolledDate").Value)%></td>
              <td><%=(rsClients.Fields.Item("ReferralType").Value)%></td>
              <td nowrap="nowrap"><%=(rsClients.Fields.Item("ReferralSource").Value)%></td>
              <td nowrap="nowrap"><%=(rsClients.Fields.Item("ReferralSourceText").Value)%></td>
              <td><%=(rsClients.Fields.Item("ReferralStaffName").Value)%></td>
              <td align="center" bgcolor="#CCCCCC">&nbsp;</td>
              <td nowrap="nowrap"><%=(rsClients.Fields.Item("DataEntryStaffName").Value)%></td>
              <td><% If Not IsNull(rsClients.Fields.Item("DataEntryDate").Value) Then Response.Write(FormatDateTime(rsClients.Fields.Item("DataEntryDate").Value,vbShortDate)) End If %></td>
              <td align="center"><%=(rsClients.Fields.Item("DataEntryDays").Value)%></td>
              <td align="center" bgcolor="#CCCCCC">&nbsp;</td>
              <td nowrap="nowrap"><%=(rsClients.Fields.Item("Intake1stContactStaffName").Value)%></td>
              <td><%=(rsClients.Fields.Item("Intake1stContactAssignedDate").Value)%></td>
              <td align="center"><%=(rsClients.Fields.Item("Intake1stContactAssignedDays").Value)%></td>
              <td><%=(rsClients.Fields.Item("Intake1stContactCompletedDate").Value)%></td>
              <td align="center"><%=(rsClients.Fields.Item("Intake1stContactCompletedDays").Value)%></td>
              <td align="center" bgcolor="#CCCCCC">&nbsp;</td>
              <td nowrap="nowrap"><%=(rsClients.Fields.Item("Intake1stScheduledStaffName").Value)%></td>
              <td><%=(rsClients.Fields.Item("Intake1stScheduledAssignedDate").Value)%></td>
              <td align="center"><%=(rsClients.Fields.Item("Intake1stScheduledAssignedDays").Value)%></td>
              <td><%=(rsClients.Fields.Item("Intake1stScheduledCompletedDate").Value)%></td>
              <td align="center"><%=(rsClients.Fields.Item("Intake1stScheduledCompletedDays").Value)%></td>
              <td align="center" bgcolor="#CCCCCC">&nbsp;</td>
              <td nowrap="nowrap"><%=(rsClients.Fields.Item("IntakeAssessorStaffName").Value)%></td>
              <td><%=(rsClients.Fields.Item("IntakeAssessorAssignedDate").Value)%></td>
              <td align="center"><%=(rsClients.Fields.Item("IntakeAssessorAssignedDays").Value)%></td>
              <td><%=(rsClients.Fields.Item("IntakeAssessorCompletedDate").Value)%></td>
              <td align="center"><%=(rsClients.Fields.Item("IntakeAssessorCompletedDays").Value)%></td>
              <td align="center" bgcolor="#CCCCCC">&nbsp;</td>
              <td nowrap="nowrap"><%=(rsClients.Fields.Item("IntakeReviewerStaffName").Value)%></td>
              <td><%=(rsClients.Fields.Item("IntakeReviewerAssignedDate").Value)%></td>
              <td align="center"><%=(rsClients.Fields.Item("IntakeReviewerAssignedDays").Value)%></td>
              <td><%=(rsClients.Fields.Item("IntakeReviewerCompletedDate").Value)%></td>
              <td align="center"><%=(rsClients.Fields.Item("IntakeReviewerCompletedDays").Value)%></td>
              <td align="center" bgcolor="#CCCCCC">&nbsp;</td>
              <td nowrap="nowrap"><%=(rsClients.Fields.Item("IntakeServicesStaffName").Value)%></td>
              <td><%=(rsClients.Fields.Item("IntakeServicesAssignedDate").Value)%></td>
              <td align="center"><%=(rsClients.Fields.Item("IntakeServicesAssignedDays").Value)%></td>
              <td><%=(rsClients.Fields.Item("IntakeServicesCompletedDate").Value)%></td>
              <td align="center"><%=(rsClients.Fields.Item("IntakeServicesCompletedDays").Value)%></td>
              <td align="center" bgcolor="#CCCCCC">&nbsp;</td>
              <td nowrap="nowrap"><%=(rsClients.Fields.Item("Intake1stSessionStaffName").Value)%></td>
              <td><%=(rsClients.Fields.Item("Intake1stSessionDate").Value)%></td>
              <td align="center"><%=(rsClients.Fields.Item("Intake1stSessionDays").Value)%></td>
            </tr>
            <% 
        Repeat1__index=Repeat1__index+1
        Repeat1__numRows=Repeat1__numRows-1
        rsClients.MoveNext()
    Wend
    %>

1 个答案:

答案 0 :(得分:0)

您需要为要铰接的列设置保留变量。这里有一些伪代码可以让你走上正确的道路:

    strClientIdHold = ""

    While  NumRows <> 0 And Not EOF
        If strClientIdHold <> rs("ClientId") Then
            <td>rs("ClientId")</td>
            <td>second column</td>
            <td>third column</td>
            <td>rs("Services")</td>
            <td>fifth column</td>
            <td>...</td>

            strClientId = rs("ClientId")
        Else
            <td colspan="3"></td>
            <td>rs("Services")</td>
            <td colspan="8"></td>
        End If

        Repeat1__index=Repeat1__index+1
        Repeat1__numRows=Repeat1__numRows-1
        rsClients.MoveNext()
    Wend

如果您希望自己也可以进行其他检查以查看其他列是否发生更改...即一个客户端ID是否可以拥有多个您想要转移的办公室或团队并显示该列?那么你也可以使用另一个保持变量。

我希望这会有所帮助。