dbTalk Databases Forums  

Help creating activeX script to insert or update records

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


Discuss Help creating activeX script to insert or update records in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jim Wile
 
Posts: n/a

Default Help creating activeX script to insert or update records - 03-07-2005 , 02:36 PM






Hello

I have used dts, but have not had to write any Activx scripts. I am trying
to update table A from table B if the vendor_number field matches, if it
does not match, I want to insert a new record into table A. Following is
the script I created, it fails with a dup key error.

any help would be greatly appreciated

Jim Wile

'************************************************* *********************
' Visual Basic Transformation Script
'************************************************* ***********************

' Copy each source column to the destination column
Function Main()

DTSDestination("VENDOR_NAME") = DTSSource("VENDOR_NAME")
DTSDestination("ADDRESS_1") = DTSSource("SYS_ADDRESS_1")
DTSDestination("ADDRESS_2") = DTSSource("SYS_ADDRESS_2")
DTSDestination("CITY") = DTSSource("SYS_CITY")
DTSDestination("STATE") = DTSSource("SYS_STATE")
DTSDestination("ZIP_CODE") = DTSSource("SYS_POSTAL_CODE")
DTSDestination("PHONE_NUMBER") = DTSSource("PHONE")
DTSDestination("ADDRESS_3") = DTSSource("SYS_ADDRESS_3")
DTSDestination("TAGS_ON_BILLS") = ("N")
If DTSDestination("VENDOR_NUMBER") = DTSSource("VENDOR_NUMBER") Then
Main = DTSTransFormstat_UpdateQuery
Else
Main = DTSTransFormstat_InsertQuery
DTSDestination("VENDOR_NUMBER") = DTSSource("VENDOR_NUMBER")
End If
' Main = DTSTransformStat_OK
End Function









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

Default Re: Help creating activeX script to insert or update records - 03-07-2005 , 02:49 PM






The problem with this is that you are comparing Vendor Number to Vendor
Number. You are doing this One row at a time so there may be matches
but not at that particular juncture.

Do this in TSQL or at least the UPDATE part if you can. It will be much
quicker.



"Jim Wile" <jimwile (AT) mopac (DOT) com> wrote


Quote:
Hello

I have used dts, but have not had to write any Activx scripts. I am trying
to update table A from table B if the vendor_number field matches, if it
does not match, I want to insert a new record into table A. Following is
the script I created, it fails with a dup key error.

any help would be greatly appreciated

Jim Wile

'************************************************* *********************
' Visual Basic Transformation Script
'************************************************* ***********************

' Copy each source column to the destination column
Function Main()

DTSDestination("VENDOR_NAME") = DTSSource("VENDOR_NAME")
DTSDestination("ADDRESS_1") = DTSSource("SYS_ADDRESS_1")
DTSDestination("ADDRESS_2") = DTSSource("SYS_ADDRESS_2")
DTSDestination("CITY") = DTSSource("SYS_CITY")
DTSDestination("STATE") = DTSSource("SYS_STATE")
DTSDestination("ZIP_CODE") = DTSSource("SYS_POSTAL_CODE")
DTSDestination("PHONE_NUMBER") = DTSSource("PHONE")
DTSDestination("ADDRESS_3") = DTSSource("SYS_ADDRESS_3")
DTSDestination("TAGS_ON_BILLS") = ("N")
If DTSDestination("VENDOR_NUMBER") = DTSSource("VENDOR_NUMBER") Then
Main = DTSTransFormstat_UpdateQuery
Else
Main = DTSTransFormstat_InsertQuery
DTSDestination("VENDOR_NUMBER") = DTSSource("VENDOR_NUMBER")
End If
' Main = DTSTransformStat_OK
End Function


Reply With Quote
  #3  
Old   
Jim Wile
 
Posts: n/a

Default Re: Help creating activeX script to insert or update records - 03-07-2005 , 03:52 PM



Thanks for replying,
I could use some help transforming this into a working script., I am just a
novice in using DTS.

Thanks
Jim Wile

"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote

Quote:
The problem with this is that you are comparing Vendor Number to Vendor
Number. You are doing this One row at a time so there may be matches
but not at that particular juncture.

Do this in TSQL or at least the UPDATE part if you can. It will be much
quicker.



"Jim Wile" <jimwile (AT) mopac (DOT) com> wrote


Hello

I have used dts, but have not had to write any Activx scripts. I am
trying
to update table A from table B if the vendor_number field matches, if it
does not match, I want to insert a new record into table A. Following
is
the script I created, it fails with a dup key error.

any help would be greatly appreciated

Jim Wile

'************************************************* *********************
' Visual Basic Transformation Script

'************************************************* ***********************

' Copy each source column to the destination column
Function Main()

DTSDestination("VENDOR_NAME") = DTSSource("VENDOR_NAME")
DTSDestination("ADDRESS_1") = DTSSource("SYS_ADDRESS_1")
DTSDestination("ADDRESS_2") = DTSSource("SYS_ADDRESS_2")
DTSDestination("CITY") = DTSSource("SYS_CITY")
DTSDestination("STATE") = DTSSource("SYS_STATE")
DTSDestination("ZIP_CODE") = DTSSource("SYS_POSTAL_CODE")
DTSDestination("PHONE_NUMBER") = DTSSource("PHONE")
DTSDestination("ADDRESS_3") = DTSSource("SYS_ADDRESS_3")
DTSDestination("TAGS_ON_BILLS") = ("N")
If DTSDestination("VENDOR_NUMBER") = DTSSource("VENDOR_NUMBER") Then
Main = DTSTransFormstat_UpdateQuery
Else
Main = DTSTransFormstat_InsertQuery
DTSDestination("VENDOR_NUMBER") = DTSSource("VENDOR_NUMBER")
End If
' Main = DTSTransformStat_OK
End Function










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

Default Re: Help creating activeX script to insert or update records - 03-08-2005 , 12:44 AM



You are going to find it really really slow to do it in this task.

Use an ExecuteSQL task to do your updates by matching on PK columns

You can then use a qualified SourceSQLStatement to do your inserts using
a DataPump task

Allan

"Jim Wile" <jimwile (AT) mopac (DOT) com> wrote


Quote:
Thanks for replying,
I could use some help transforming this into a working script., I am just a
novice in using DTS.

Thanks
Jim Wile

"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote in message
news:%23RgwDa1IFHA.3500 (AT) TK2MSFTNGP14 (DOT) phx.gbl...
The problem with this is that you are comparing Vendor Number to Vendor
Number. You are doing this One row at a time so there may be matches
but not at that particular juncture.

Do this in TSQL or at least the UPDATE part if you can. It will be much
quicker.



"Jim Wile" <jimwile (AT) mopac (DOT) com> wrote


Hello

I have used dts, but have not had to write any Activx scripts. I am
trying
to update table A from table B if the vendor_number field matches, if it
does not match, I want to insert a new record into table A. Following
is
the script I created, it fails with a dup key error.

any help would be greatly appreciated

Jim Wile

'************************************************* *********************
' Visual Basic Transformation Script

'************************************************* ***********************

' Copy each source column to the destination column
Function Main()

DTSDestination("VENDOR_NAME") = DTSSource("VENDOR_NAME")
DTSDestination("ADDRESS_1") = DTSSource("SYS_ADDRESS_1")
DTSDestination("ADDRESS_2") = DTSSource("SYS_ADDRESS_2")
DTSDestination("CITY") = DTSSource("SYS_CITY")
DTSDestination("STATE") = DTSSource("SYS_STATE")
DTSDestination("ZIP_CODE") = DTSSource("SYS_POSTAL_CODE")
DTSDestination("PHONE_NUMBER") = DTSSource("PHONE")
DTSDestination("ADDRESS_3") = DTSSource("SYS_ADDRESS_3")
DTSDestination("TAGS_ON_BILLS") = ("N")
If DTSDestination("VENDOR_NUMBER") = DTSSource("VENDOR_NUMBER") Then
Main = DTSTransFormstat_UpdateQuery
Else
Main = DTSTransFormstat_InsertQuery
DTSDestination("VENDOR_NUMBER") = DTSSource("VENDOR_NUMBER")
End If
' Main = DTSTransformStat_OK
End Function



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.