Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Driven Queries 2

Status
Not open for further replies.

Katy44

Technical User
Dec 12, 2003
723
GB
Hi,
I'm trying to set up a data driven query. I have my two connections, a data driven query task and and an activeX script task.
What is the order that these should be in?
I actually want to check whether, for each record from the source, a primary key exists in the destination, then if it does, I want to update, else to insert. Does anyone know of any good examples of this?
 
Try added a lookup to your data driven query. The lookup will perform a select statement on the table you want to test for.

Ex:
Code:
Select Any_column
FROM   PK_Table
WHERE  PK_value = ?

In the ActiveX script that moves source to destination, set a variable equal to this lookup value passing the PK_value as a parameter. If the value exists, execute update query. If not execute insert query.

Ex:
Code:
Function Main()

Dim strPKValue

	strPKValue = DTSLookups("PK_Test").Execute(DTSSource("Col001"))

	'  If record already exists, update values
	if strPKValue <> "" then
		DTSDestination("First_Name") = DTSSource("Col002")
		DTSDestination("Last_Name") = DTSSource("Col003")
		DTSDestination("Middle_Init") = DTSSource("Col004")
		Main = DTSTransformStat_UpdateQuery

	' else, insert record
	else
		DTSDestination("Assoc_ID") = DTSSource("Col001")
		DTSDestination("First_Name") = DTSSource("Col002")
		DTSDestination("Last_Name") = DTSSource("Col003")
		DTSDestination("Middle_Init") = DTSSource("Col004")
		Main = DTSTransformstat_InsertQuery
	end if
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top