Guidelines for using custom macros
Keep the following guidelines in mind when creating or using a custom macro:
*
*
If a data source has been configured with the property ENABLE_SELECT_SORT_BY = TRUE, then you must write raw SQL custom macros with an ORDER BY clause in order to sort the returned records by the audience key fields of the audience level under which you are working. Otherwise, if the sort order is not as expected, an error will be generated when the custom macro is used in a derived field in a Snapshot process.
*
*
When a custom macro uses temp tables in its underlying logic, a temp table will be forced up to the database so that the logic does not fail.
However, if a custom macro is used in a top level SELECT, then there is no history for Campaign to use to force a temp table up to the database, and the logic fails.
Thus, when creating a custom macro that uses raw SQL, you might need to create two versions of the same custom macro - one that uses temp table tokens and one that does not.
The custom macro without temp table tokens can be used at the top of a tree (for example, in the first SELECT). The one with temp table tokens can be used anywhere else in the tree when there might be a temp table to take advantage of.
*
For example, if you a use a custom macro based on raw SQL that returns a value and (in a Snapshot process, for example) you output the custom macro and another field from the table that the custom macro is based on, Campaign performs a self join on that table. If the table is non-normalized, you will end up with a Cartesian product (that is, the number of records displayed is more than you would expect).
*
At execution time, a custom macro is resolved by looking up its definition in the UA_CustomMacros system table (where definitions are stored) and then used/executed.
*
Campaign supports stored queries from earlier releases. However, references to non-unique stored queries must use the old syntax:
storedquery(<query name>)
*
When resolving user variables in custom macros, Campaign uses the current value of the user variable when checking syntax. If the current value is left blank, Campaign generates an error.
*
*
If you intend to use the custom macro across several different databases, you might want to use a IBM® expression rather than raw SQL, since raw SQL can be specific to a particular database.
*
*
Campaign treats a comma as a parameter separator. If you are using commas as literal characters in a parameter, enclose the text in open and close brackets ({}), as in the following example:
TestCM( {STRING_CONCAT(UserVar.Test1, UserVar.Test2) } )
*
Campaign supports simple substitution for parameters in custom macros using raw SQL code. For example, if you set up a Select process box on a flowchart containing this query:
exec dbms_stats.gather_table_stats(tabname=> <temptable>,ownname=> 'autodcc')
Campaign would successfully substitute the actual temp table in place of the <temptable> token. Note that the single quotes around the table name are required.
The following tables show how Campaign treats custom macros in queries and derived fields.
Custom macros in queries and derived fields (Select, Segment, and Audience Processes)
If the value is not used this way, Campaign treats a non-zero value as TRUE for ID selection and a zero value and string as FALSE.
IBM® Expression
In a Raw SQL Query (Select, Segment, and Audience Processes)
IBM® Expression