The following two samples demonstrate how you can use parameterized SQL statements and Microsoft® ActiveX® Scripts to create single-key database lookups using DTS Designer in SQL Server Enterprise Manager.
This sample uses au_lname in a query as a key to get new_lname from the author_lookup table and return it to a script transformation for insertion into the destination column au_lname.
SELECT new_lname
FROM author_lookup
WHERE (au_lname = ?)
Note You must use a connection for the lookup other than the one used for source and destination.
Note You only need to specify DTS ActiveX Script Transformation for those columns that are used in the lookup. You can specify DTS Column Copy Transformation for the other columns.
Function Main()
DTSDestination("au_lname") = DTSLookups("myLookup").Execute(DTSSource("au_lname").Value)
Main = DTSTransformStat_OK
End Function
This sample uses au_lname in a query as a key to get new_lname from the source table and returns au_id to a script transformation for insertion into the destination column.
SELECT au_id
FROM author_lookup
WHERE (au_lname = ?)
Note The source column, au_id, does not require a mapping because the lookup uses the source column, au_lname, to retrieve an au_id value from the lookup table to insert into destination au_id column. You can specify DTS Column Copy Transformation for all other columns.
Function Main()
DTSDestination("au_id") = DTSLookups("myLookup").Execute(DTSSource("au_lname").Value)
Main = DTSTransformStat_OK
End Function