colunion(X;Y)
Returns a string consisting of the union of values from a given set of columns concatenated together using the specified separator, sorted in ascending order.
Syntax
colunion(X;Y)
Input
Argument | Type | Description |
---|---|---|
X |
any | A list of column names |
Y |
text | One or more characters to be used as the separator |
Return Value
For each row of the table, colunion
returns the text string consisting of
the union of the values for that row from all columns in X
, concatenated
together using the separator specified by Y
. The values in the resultant
string are sorted in ascending order. Duplicate values are eliminated in the union. This
function provides a way of combining the values of several columns into one column.
N/A values are ignored.
Sample Usage
values |
sep |
colunion(values;sep) |
---|---|---|
'dog' 'cat' 'dog' | ',' | 'cat,dog' |
Example
In the "Product Master" table (pub.demo.retail.prod), let's say we
wanted to create a computed column that consisted of the division (div
),
department number (dept
), and department description
(deptdesc
), separated by slashes ("/
"). We could do this
by using the colunion(X;Y)
function and specifying the three column names
in the list for the X
parameter and the slash for the Y
parameter.
<base table="pub.demo.retail.prod"/> <willbe name="colunion_results" value="colunion(dept div deptdesc;'/')"/> <colord cols="colunion_results"/>
This would give us the following results:
dept
, div
, and deptdesc
,
colunion
orders the results in ascending order. So, in our example, the
results are ordered: div
, dept
, and
deptdesc
.