Click or drag to resize
SQL_OrgUnitDescendant

[This is preliminary documentation and is subject to change.]

The TOPICA Basic function SQL_OrgUnitDescendant is used generate an SQL-snippet to call an SQL function (stored in the database) to check if one organizational unit is descendant of some other organizational unit.

The data model in the TOPICA database contains a hierarchical data model for the organization. The organization is made up of organizational units. Each organizational unit (except the root in the hierarchy) has a reference to its parent organizational unit.

This makes it easy - by using SQL - to find the immediate parent or all the immediate children of any organizational unit. However, it is not straightforward to find ALL ancestors or ALL descendants of a given organizational unit.

To address this issue, the database contains a table called OrgUnitLineage, which holds relations between any ancestor/descendent pair. To extract data using SQL (e.g. to build reports), you have the following options:

  • Join with table OrgUnitLineage.

  • Refer the SQL function dbo.CheckOrgUnitIsDescendant in your SQL query.

  • Use TOPICA Basic to construct the query. In this case you may use the TOPICA Basic function SQL_OrgUnitDescendant to "wrap" call to SQL function dbo.CheckOrgUnitIsDescendant.

Syntax
SQL_OrgUnitDescendant(ancestorType, ancestorCode, descendantType, descendantCode)
Parameters

Name

Type

Description

ancestorType

String

Name of the database field holding the type of the ancestor organizational unit.

ancestorCode

String

Name of the database field holding the code of the ancestor organizational unit.

descendantType

String

Name of the database field holding the type of the descendant organizational unit.

descendantCode

String

Name of the database field holding the code of the descendant organizational unit.

Returns

SQL comparison expression.

Type: String.

Examples
SQL_OrgUnitDescendant("ancestorType", "ancestorCode", "descendantType", "descendantCode")

Result: "dbo.CheckOrgUnitIsDescendant(ancestorType,ancestorCode,descendantType,descendantCode) = 1 "

Note:

  • The database function CheckOrgUnitIsDescendant is defined in the dbo schema.

    The database function CheckOrgUnitIsDescendant returns the value 1, if the organizational unit specified by (descendantType, descendantCode) is descendant of the organizational unit specified by (ancestorType, ancestorCode).