2017-09-20 5 views
1

J'utilise MS SQL Server 2014 et Coldfusion 10 et je rencontre un problème de publication sur ma table. Mon total associé pour certains utilisateurs sur ma table est ignoré lorsque le fichier PDF est créé. Est-ce que quelqu'un sait ce que je fais de mal qui ferait en sorte que le champ Associate Total soit simplement ignoré pour quelques utilisateurs?Table CF ignorer les lignes lors de la création de la table

<cfset date1 = CREATEODBCDATETIME(form.StartDate & '00:00:00')> 
<cfset date2 = CREATEODBCDATETIME(form.EndDate & '23:59:59')> 

<!--- WHITELIST OF VALID LOCATIONS ---> 
    <cfset validLocs = "OPERATIONS, CCC, QA, DS, PS, LWR, NR, SDL, FSC"> 
    <cfset locList = ""> 
    <cfif structKeyExists(FORM,"location") AND len(FORM.location) GT 0> 
     <cfloop list="#FORM.location#" index="vLoc"> 
      <cfif listContainsNoCase(validLocs, vLoc) GT 0> 
      <cfset locList = listAppend(locList,vloc)> 
      </cfif> 
     </cfloop> 
    <cfelse> 
    </cfif> 


<cfquery datasource="#application.dsn#" name="GetEmployeeInfo"> 
    SELECT * 
     FROM ( 
     SELECT t1.associate 
     , a.assoc_name 
     , t1.trans_location 
     , t1.checklistsByAssocLoc 
     , t1.totalChecklistsByAssoc 
     , CASE WHEN (coalesce(t1.totalChecklistsByAssoc,0) > 0) THEN (CAST(t1.checklistsByAssocLoc AS decimal(8,2))/t1.totalChecklistsByAssoc) * 100 ELSE 0 END AS totalChecklistsByAssocLocPct /* This gives you a percent of associate location checklists over count of checklists by Associate */ , t1.totalChecklistsByLoc 
     , CASE WHEN (coalesce(t1.totalChecklistsByLoc,0) > 0) THEN (CAST(t1.checklistsByAssocLoc AS decimal(8,2))/t1.totalChecklistsByLoc) * 100 ELSE 0 END AS totalChecklistsByLocPct /* This gives you a percent of associate location checklists over count of checklists by Location */ 
     , ROW_NUMBER() OVER (PARTITION BY associate ORDER BY associate, trans_location) AS rnA 
     , ROW_NUMBER() OVER (PARTITION BY associate, trans_location ORDER BY trans_location) AS rnL 
     , t1.rnTotAssoc 
     FROM ( 
     SELECT c.associate 
     , c.trans_location 
     , COUNT(*) OVER (PARTITION BY c.associate, c.trans_location) AS checklistsByAssocLoc /* Gives you a count of checklists by Associate and Location >> I think this is 1.1 locCntr */ 
     , COUNT(*) OVER (PARTITION BY c.associate) AS totalChecklistsByAssoc /* Gives you a count of checklists by Associate */ 
     , COUNT(*) OVER (PARTITION BY c.trans_location) AS totalChecklistsByLoc /* Gives you a count of checklists by Location */ 
     , ROW_NUMBER() OVER (PARTITION BY c.associate ORDER BY c.trans_location DESC) AS rnTotAssoc 
     FROM cl_checklists c 
     WHERE c.[DATE] >= <cfqueryparam value="#date1#" cfsqltype="cf_sql_timestamp" /> 
     AND c.[DATE] <= <cfqueryparam value="#date2#" cfsqltype="cf_sql_timestamp" /> 
     AND c.trans_location IN (<cfqueryparam value="#locList#" cfsqltype="cf_sql_varchar" list="true" /> ) 
    ) t1 
     INNER JOIN tco_associates a ON t1.associate = a.assoc_id 
    ) s2 
     WHERE s2.rnA = 1 OR s2.rnL = 1 
     ORDER BY s2.assoc_name, s2.trans_location 
</cfquery> 

<cfif GetEmployeeInfo.recordcount is 0> 

<td width="85%" valign="top" class="mainmodule"><p class="pageheader">CHECKLIST STATS REPORT</p><br /> 
    No matching records found 
</td> 
</tr> 
</table> 

</body> 
</html> 

<cfelse> 

<cfif FORM.Format IS "print"> 

<cfdocument format="pdf" scale="75" backgroundvisible="yes" overwrite="no" fontembed="yes"> 

<td width="85%" valign="top" class="mainmodule"><p class="pageheader">CHECKLIST STATS REPORT</p><br /> 

<style type="text/css"> 
    table{ 
     text-align:center; 
    } 
</style> 

<table> 
    <thead> 
     <th><strong>Associate Name</strong></th> 
     <th><strong>Location</strong></th> 
     <th><strong>Checklists Generated by Associate</strong></th> 
     <th><strong>Checklists Generated by Selected Location(s)</strong></th> 
     <th><strong>Associate Percentage of Location Total</strong></th> 
    </thead> 
    <tbody> 
     <cfoutput query="GetEmployeeInfo"> 
     <tr> 
      <td><cfif rnA EQ 1><strong>#assoc_name#</strong></cfif></td> 
      <td><cfif rnL EQ 1>#trans_location#</cfif></td> 
      <td>#checklistsByAssocLoc#</td> 
      <td>#totalChecklistsByLoc#</td> 
      <td>#DecimalFormat(totalChecklistsByLocPct)# %</td> 
     </tr> 
     <cfif rnTotAssoc EQ 1> 
     <tr> 
      <td>Associate Total</td> 
      <td></td> 
      <td>#totalChecklistsByAssoc#</td> 
      <td>#totalChecklistsByLoc#</td> 
      <td>#DecimalFormat(totalChecklistsByLocPct)# %</td> 
     </tr> 
     </cfif> 
    </cfoutput> 
    </tbody> 
</table> 

</cfdocument> 

</cfif> 

</cfif> 

Les résultats devraient ressembler à:

Brierton, David SDL 1 32195 0.00 % 
Associate Total  1 32195 0.00 % 

Certains sont MONTRANT simplement:

Brierton, David SDL 1 32195 0.00 % 
+0

À quoi 'rnTotAssoc' est-il égal dans ce cas? –

+0

il est égal à 1 –

+0

bien que ceux qui travaillent sont égaux à 1 les autres ne montrent pas donc je ne sais pas ce qu'il ya –

Répondre

1

Cette requête semble correcte. RnA = 1 donnera les lignes qui incluent la première instance d'un nom d'associé.

RnL = 1 donnera des lignes pour la première instance de l'emplacement.

RnTotAssoc = 1 donnera la dernière ligne d'un associé, y compris ses emplacements. La ligne suivante doit afficher un total des enregistrements associés. Chaque associé doit avoir au moins 1 enregistrement avec rnTotAssoc = 1.

http://sqlfiddle.com/#!6/56892/10

Avez-vous des données incorrectes qui est chambouler les résultats? Essayez de distinguer une ou deux personnes et de trouver ce qui devrait être leur nombre correct. Vous pouvez supprimer WHERE s2.rnA = 1 OR s2.rnL = 1 de la requête pour voir toutes les lignes qui entrent dans ces comptes.

+0

Tant qu'une ligne vaut 1 pour rnA, rnL et rnTotAssoc, cela ne devrait pas avoir d'importance. Si ce nombre n'est pas 1, SQL l'a trié dans un ordre différent pour générer ce nombre. – Shawn

+0

Prenez l'associé dont l'enregistrement n'a pas été affiché et recherchez spécifiquement cet associé dans la requête. Voir quelles lignes sont disponibles pour cet associé. Changez WHERE à 'WHERE s2.assoc_name = '' ou s2.associate = '. – Shawn