dbTalk Databases Forums  

Check for primary key violation

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Check for primary key violation in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
tjonsek@phenom-biz.com
 
Posts: n/a

Default Check for primary key violation - 01-23-2006 , 10:48 AM






I have a package that exports records from a linked server into a table
on the current server. I would like to add a piece of code to skip a
row if that key is already in the table. I attempted this but got a
type mismatch error on 'DTSSource'.
Here's the code snippet I attempted:
if (DTSSource("Emp_PK") = DTSDestination("EmpEvt_EmpFK") and
DTSSource("Evt_PK") = DTSDestination("EmpEvt_EvtFK")) then
Main = DTSTransformStat_SkipRow
end if

If I can't accomplish this, I thought perhaps I could add code that
would skip any rows that cause an error, but I'm not sure of the wisdom
in this. Nor, am I sure about the syntax for activex script.

I've double checked and my field names are typed correctly. I've not
attempted this before. Any tips or suggestions would be greatly
appreciated.
Thanks
TJ


Reply With Quote
  #2  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Check for primary key violation - 01-23-2006 , 02:48 PM






Hello tjonsek (AT) phenom-biz (DOT) com,

I would not be doing it like this. The way you suggest processes rows 1*1.
This will hurt. If you are already using Linked servers then in your Source
Query for the datapump task you simply add a join between the source table
and the destination table and make sure that the source row is not already
in the destination. This way you do not need to process each row individually

Allan


Quote:
I have a package that exports records from a linked server into a
table
on the current server. I would like to add a piece of code to skip a
row if that key is already in the table. I attempted this but got a
type mismatch error on 'DTSSource'.
Here's the code snippet I attempted:
if (DTSSource("Emp_PK") = DTSDestination("EmpEvt_EmpFK") and
DTSSource("Evt_PK") = DTSDestination("EmpEvt_EvtFK")) then
Main = DTSTransformStat_SkipRow
end if
If I can't accomplish this, I thought perhaps I could add code that
would skip any rows that cause an error, but I'm not sure of the
wisdom in this. Nor, am I sure about the syntax for activex script.

I've double checked and my field names are typed correctly. I've not
attempted this before. Any tips or suggestions would be greatly
appreciated.
Thanks
TJ



Reply With Quote
  #3  
Old   
tjonsek@phenom-biz.com
 
Posts: n/a

Default Re: Check for primary key violation - 01-23-2006 , 02:55 PM



Ok. I understand what you are saying and I understand your explanation,
just not how to execute it. I apologize. I've not attempted this
before, so I'll do a bit of reading online if I can find anything for
datapump tasks.
If you know any good sources, please let me know.
Thanks


Reply With Quote
  #4  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Check for primary key violation - 01-23-2006 , 02:58 PM



Hello tjonsek (AT) phenom-biz (DOT) com,

www.SQLDTS.com is generally considered useful.

in the datapump task instead of specifying a table as the source you are
going to use a query that will retrieve the source rows that are not already
in the destination (LEFT OUTER JOIN, NOT IN, NOT EXISTS)

Allan

Quote:
Ok. I understand what you are saying and I understand your
explanation,
just not how to execute it. I apologize. I've not attempted this
before, so I'll do a bit of reading online if I can find anything for
datapump tasks.
If you know any good sources, please let me know.
Thanks



Reply With Quote
  #5  
Old   
tjonsek@phenom-biz.com
 
Posts: n/a

Default Re: Check for primary key violation - 01-23-2006 , 03:15 PM



Ok. I get you. Thanks so much. I'll check out the website! Earlier I
had tried an if exists statement, but obviously didn't have everything
correct.

I appreciate it.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.