Custom SQL Expressions
A custom SQL expression can be added to a standard selection rule using the Add Custom SQL Expression dialog.
![](../__attachments/3904936931/att_3_for_3862822942.png?inst-v=c3007bf4-8f91-43d3-9633-90859273c945)
It contains the following:
Query table: you must select the table against which the expression is to be executed, using the Choose Database Item dialog. If the current RPI tenant is configured with one or more auxiliary databases, the dialog lists only those tables within the database matching the current standard selection rule’s resolution level.
Query after WHERE clause: this multiline field allows you to define the SQL expression, provision of which is mandatory. The expression should take the form of a SQL WHERE clause (e.g. “Gender = 'F’”). By default, the following reserved strings are not permitted within the expression:
;
insert
delete
drop
–
truncate
update
%3B
union
create
exec
The default set of reserved strings can be overridden by setting application setting Override Custom SQL Reserved Words to True, and by specifying a list of reserved strings using application setting Custom SQL Reserved Words. If this is supplied, the existing reserved strings no longer apply.
You can use the following syntax within the Query to reference the Query table: “{alias}.”
Validate: this button allows you to test to ensure that the SQL you entered is valid. It is available when characters are present in Query after WHERE clause. When you select the button, it is initially unavailable as it creates a Validate SQL Expression job (the My Jobs Dialog is not shown). If the SQL is valid, the property appears as follows:
![](../__attachments/3904936931/att_1_for_3862822942.png?inst-v=c3007bf4-8f91-43d3-9633-90859273c945)
If the SQL not is not valid, the following are shown:
![](../__attachments/3904936931/att_2_for_3862822942.png?inst-v=c3007bf4-8f91-43d3-9633-90859273c945)
You can amend the SQL and select the button again to re-validate. Note that the SQL you enter need not be valid for you to select Finish.
On selecting Finish, the custom SQL expression is added to the standard selection rule at the context of invocation. It is displayed as “Custom SQL Expression”.
If the selected Query table is not the same as the standard selection rule’s resolution table, the expression is added within a criteria list.
Having added a custom SQL expression, you can subsequently configure it to change its details.
Note that the ability to add a custom SQL expression is controlled by functional permission Selection Rule – Standard – Custom SQL Expression.