Group-By Function

Top Previous Topic Next Topic  Print this topic

Group-By function selects records that generate distinct values for a specified field. The following example lists the department history count for each employee. Note that only one data source is used (sql-data-source which joins emp and hist table). Distinct employee IDs are generated using the group-by funtion. The department count is computed using a filter function that filters the initial data source according to the current employee ID.

 

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<das:job xmlns:das="http://www.ecrion.com/das/1.0" last-id="48">

 

       <!--The resulting xml structure-->

       <das:output id="1">

               <das:element id="2" name="root">

                       <das:element-sequence id="a" name="employee" data-source="1f">

                               <das:attribute id="c" name="name" value="f"/>

                               <das:attribute id="1e" name="deptcount" value="2b"/>

                       </das:element-sequence>

               </das:element>

       </das:output>

       

       <das:concat-function id="e">

               <das:in-param id="11" name="string" src="8"/>

               <das:in-param id="14" name="string" src="16"/>

               <das:in-param id="18" name="string" src="7"/>

               <das:return-value id="f"/>

       </das:concat-function>

       

       <das:const-function id="15">

               <das:const-return-value id="16" value=" " type="string"/>

       </das:const-function>

       

       <das:equal-function id="25">

               <das:in-param id="28" src="1000"/>

               <das:in-param id="27" src="9"/>

               <das:return-value id="26"/>

       </das:equal-function>

       

       <das:count-function id="2a" data-source="23">

               <das:return-value id="2b"/>

       </das:count-function>

       

       <das:sql-data-source id="4" select="SELECT emp.ID, emp.FIRST_NAME, emp.LAST_NAME, Hist.DEPARTMENT, Hist.DATE_MODIFIED     FROM emp LEFT JOIN Hist ON emp.id = Hist.emp_id     ORDER BY Hist.DATE_MODIFIED" connection="3">

               <das:field id="5" name="DATE_MODIFIED"/>

               <das:field id="6" name="DEPARTMENT"/>

               <das:field id="7" name="LAST_NAME"/>

               <das:field id="8" name="FIRST_NAME"/>

               <das:field id="9" name="ID"/>

       </das:sql-data-source>

 

       <!--Generate distinct ID's from input data-source(4)-->        

       <das:group-by-function id="1f" data-source="4" filter="9">

               <das:field id="1000" name="##key"/>

       </das:group-by-function>

       

       <!--Filters  input data-source(4) after the current generated employee ID!-->

       <das:filter-function id="23" data-source="4" filter="26"/>

       

       <das:database-connections>

               <das:database-connection id="3" connection-string="#connectionString" data-driver-type="DotNet" provider-name="System.Data.OleDb" description="MSACCESS:CONNECTION1"/>

       </das:database-connections>

 

</das:job>

 

Note. This sample can be found in Samples\Job Samples folder.

 

Attributes:

id - unique identifier of this resource in the current processing job.

data-source - the data source iterated by this function.

filter - data source field after which the grouping will be done.