Certain rules and guidelines apply when you override a lookup query.
Consider the following guidelines when you override the lookup SQL query:
You can override the lookup SQL query for relational lookups.
Generate the default query, and then configure the override. This ensures that all the lookup/output ports are included in the query. If you add or subtract ports from the SELECT statement, the session fails.
Add a source lookup filter to filter the rows that are added to the lookup cache. This ensures that the Integration Service inserts rows in the dynamic cache and target table that match the WHERE clause.
If multiple Lookup transformations share a lookup cache, use the same lookup SQL override for each Lookup transformation.
When you configure a Lookup transformation that returns all rows, the Integration Service builds the lookup cache with sorted keys. When the transformation retrieves all rows in a lookup, the Integration Service builds the data cache with the keys in sorted order. The Integration Service cannot retrieve all the rows from the cache if the rows are not sorted. If the data is not sorted on the keys, you might get unexpected results.
The ORDER BY clause must contain the condition ports in the same order they appear in the Lookup condition.
If you override the ORDER BY clause, use the comment notation to suppress the ORDER BY clause that the Lookup transformation generates.
If you use pushdown optimization, you cannot override the ORDER BY clause or suppress the generated ORDER BY clause with comment notation.
If a table name or column name in the lookup query contains a reserved word, enclose the reserved word in quotes.
To override the lookup query for an uncached lookup, choose to return any value when the Integration Service finds multiple matches.
You cannot add or delete any columns from the default SQL statement.