Link to home
Start Free TrialLog in
Avatar of razorhazor
razorhazor

asked on

Use DTS in VB6 EXE to transfer data when some records already in Table (PK Voilation)

Hi

I've coded an EXE which opens an ADO connection to various OLEDB/ODBC data sources and transfers the records, depending on the SQL statement used record at a time into a SQL server database.

Problem is, its very slow!

A typical example of the SQL used is, "SELECT * WHERE rowDate = TODAY", and this statement will be executed every half hour so that the table is populated Intra-Day.

We've executed DTS packages to do the same thing and have noticed the significant speed advantages you can get with DTS, problem is, the DTS job is successful the first time, but will always error out the second time as some records are already in the database (and we need them to update every half hour).

Deleting and re-importing isnt an option, some of the tables are huge and we just get SQL Timeouts (even at 300 seconds).

Is there a way to use DTS to transfer the data and ignore the records with a Primary Key violation (ie duplicates)?

Or can we say do an insert into SQL Database where Unique identifer not in table?  Ie. SELECT * FROM (database A) where ID not in (Database B)? However I cant see how this will work as all the datasources are completely different and none of the primary keys will be the same.

Any help would be greatly appreciated.!

Thanks experts!
Matt
Avatar of Partha Mandayam
Partha Mandayam
Flag of India image

Use an Activexscript
check for id in the destination table
If dtsdestination("id") exists
set the dtstransformstat_skipinsert flag to skip inserting that row.
Avatar of arbert
arbert

You wouldn't even have to use ActiveX script.  Code ExecuteSQL statements that use INSERT/UPDATE queries based upon the key already existing in the table .
Several different ways you could do it--to just find not existing records:

SELECT * WHERE rowDate = TODAY"
and yourkey not exist in (select 1 from yourtable table1 inner join yourtable  table2 where table1.primarykey=table2.primarykey)
For each table transformation implement this type of sql statement replacing the Composite Members with your primary key combination.
 
Select <unnull-column>,... from TableA left outer join TableB
on A.CompositeMember1= B.CompositeMember1 and
on A.CompositeMember2= B.CompositeMember2 and
on A.CompositeMember3= B.CompositeMember3 where
<unnull-column> is Null

This should alleviate your problems unless the primary keys are duplicated from source to source. If this is the case add a column to table to specify the source. Then when you are transforming your information into the destination table, set the source using an alias such as select 1 as iSource, ...from...table name.

Late,
Avatar of razorhazor

ASKER

Hi guys,

thanks for that, problem with joins though is that the data would be in seperate databases on seperate servers so I wouldnt have thought I would be able to code that in the same SQL statement?

Are we suggesting that I put the data into a temp table to begin with, then run the SQL statement to see whats not there?

Any chance of some example code to get my head round it?!?

Thanks for all your help
Matt
ASKER CERTIFIED SOLUTION
Avatar of arbert
arbert

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial