Solved

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

Posted on 2004-09-29
10
305 Views
Last Modified: 2011-10-03
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
0
Comment
Question by:razorhazor
10 Comments
 
LVL 6

Expert Comment

by:mcp111
ID: 12183455
Use an Activexscript
check for id in the destination table
If dtsdestination("id") exists
set the dtstransformstat_skipinsert flag to skip inserting that row.
0
 
LVL 34

Expert Comment

by:arbert
ID: 12184090
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 .
0
 
LVL 34

Expert Comment

by:arbert
ID: 12184103
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)
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 5

Expert Comment

by:MichaelSFuller
ID: 12186946
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,
0
 

Author Comment

by:razorhazor
ID: 12187783
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
0
 
LVL 34

Accepted Solution

by:
arbert earned 250 total points
ID: 12189641
You can code the join (either via linked server or openrowset), but you need to check the query plan to see if the performance is good enough.
0
 
LVL 5

Assisted Solution

by:MichaelSFuller
MichaelSFuller earned 250 total points
ID: 12189867
Example:

(Select <unnull-column>,... from Table) as A left outer join
(SELECT a.*
FROM OPENROWSET('SQLOLEDB','Servername';'username';'password',
'SELECT * FROM TableB'))
AS B
on A.CompositeMember1= B.CompositeMember1 and
on A.CompositeMember2= B.CompositeMember2 and
on A.CompositeMember3= B.CompositeMember3 where
A.<unnull-column> is Null

0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question