To configure a simple lookup query, complete the following steps:
Although a lookup query can share a connection with the source or destination under certain conditions, the best performance occurs when it is given its own connection.
The parameterized query can be a stored procedure invocation or a SELECT, INSERT, DELETE, or UPDATE statement. Mark parameters by including question marks in place of expressions that will be set at runtime. Parameter values typically come from source data but may be supplied by global variables or any other terms accessible to Microsoft® ActiveX® script code.
The query is executed with the following statement:
return value = DTSLookups("query name").Execute(argument list)
where return value is a variant that receives the result of the query, query name is the name you provided the query in step two, and argument list is a comma-separated list of parameter values, one for each question mark in the query.
Before you configure a lookup query, consider the following:
In this example, you have source data that includes a postal code but no city. A Mail Codes table contains a row for each postal code and a column for city name. The procedure for including this city name in your destination rows is as follows:
SELECT City FROM MailCodes WHERE PostalCode = ?
When you configure the lookup query, you are required to provide a connection name and a query name. Use the connection you created in step one, and name your query GetCity
.
DTSDestination("City") = DTSLookups("GetCity").Execute(DTSSource("PostalCode"))
The postal code is drawn from the source row. Its value replaces the question mark each time the query is executed.
Sometimes a lookup query takes more than one argument. For example, when:
To configure a lookup query with multiple arguments, you must:
In this example, you need to retrieve a city name, given the postal code and country. The GetInternationalCity
query has two parameters:
SELECT City FROM MailCodes WHERE PostalCode = ? AND Country = ?
In your ActiveX script, values are provided for the postal code and the country:
DTSDestination(City) = DTSLookups("GetInternationalCity").Execute _
(DTSSource("PostalCode"), DTSSource("Country"))
Sometimes you want to retrieve multiple values with a single lookup (for example, when you have a customer account number and need a name and address).
Data Transformation Services (DTS) handles multiple columns in query results by returning an array of variants. Each entry in the array holds one result value. The index of the first value is 0.
In this example, you need to retrieve a city and a region, given the postal code. The GetCityAndRegion
query selects both required columns:
SELECT City, Region FROM MailCodes WHERE PostalCode = ?
The returned values are accessed through the following ActiveX script code:
dim varArray
varArray = DTSLookups("GetCityAndRegion").Execute(DTSSource("PostalCode"))
DTSDestination("City") = varArray(0)
DTSDestination("Region") = varArray(1)