Link to home
Start Free TrialLog in
Avatar of dsachtleben
dsachtleben

asked on

Autofill an identitly field using an activex script in DTS

I have a vbscript that copies and transforms data from an access table to and existing MSSQL table. The destination table has an identity column, and I need to autopopulate it as the data is loaded. I'm thinking the line of code would look something like:

DTSDestination("id") = ?

where ? is a command to autoincrement the id by 1. Hopefully this is just a syntax question. Thanks.
Avatar of nmcdermaid
nmcdermaid

Use the DTS Package Properties dialog to create a global variable. This global variable can then be accessed in code.


For example:


Function Main()
   DTSDestination("FieldName") = DTSGlobalVariables("NewID").value
   DTSGlobalVariables("NewID").value = DTSGlobalVariables("NewID").value + 1
   Main = DTSTaskExecResult_Success
End Function



ASKER CERTIFIED SOLUTION
Avatar of nmcdermaid
nmcdermaid

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
Avatar of dsachtleben

ASKER

Thanks for help! I am obviously new to DTS but this was a very clear solution.
Don't get too familiar! It will probably change next version of SQL Server! than again that is a couple of years away.

There are a lot of handy exmpaples here: SQLDTS.COM