2016-04-01 181 views
1

我遇到了一個問題,我需要完成一些任務,但從來沒有使用過它的經驗。我目前正在運行一個asp網站,並使用SQL Server作爲數據庫。我有一個報告,我從篩選器頁面獲取查詢,然後根據查詢字符串提供信息。這是一份進口報告,因此應該只有一個訂單項,並且每個客戶端帽子的記錄出現在報告中。在報告中提供的信息包括首次聯繫的日期以及客戶何時開始與我們合作。我在稱爲服務的報告中添加了一個新字段。一個客戶有很多服務是可能的也是比較常見的。這是我需要完成的。我需要將該客戶端的每項服務列入報告中的單個數據單元格,而不顯示該客戶端的多個訂單項。我在想,可以通過使用BOF和EOF來完成答案,但我不確定如何對其進行刺探。這裏是已經在報表上的RecordSet,它包含除新字段外的每個字段,因爲我試圖爲該字段創建一個新的RecordSet。下面是希望給我想要完成的想法的圖像。非常感謝您的意見!SQL中的SQL Server報告

這張圖像就是它現在的樣子...我想把所有顯示爲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 
    %> 

回答

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也有多個辦公更或團隊,你會想轉到並顯示該列呢?然後,您將擁有另一個保持變量。

我希望這會有所幫助。