Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server DTS
|
SQL Server DTS Discussion specific to Data Transformation Service with SQL Server. General SQL Server discussions should use the general SQL Server forum. Readers of the book Professional SQL Server 2000 DTS with questions specific to that book should post in that book forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server DTS section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 28th, 2005, 06:51 AM
Registered User
 
Join Date: Sep 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Getting @@IDENTITY in Row Transform

I'm pretty new to DTS adn I have the following situation that I hope you can help with: -

I have 2 tables: -
Locations
 ID, sequential identity seed
 Code, nvarchar
 Desc, nvarchar
 AdminID, int

AdminDetails
 ID, sequential identity seed
 Street, nvarchar
 PostCode, nvarchar

I am bringing all the relevant data over in a CSV file.

The field AdminID on the Locations table is actaully the ID of the AdminDetails table. And hering lies my problem. I know how to insert into the 2 tables (using DTSTransformstat_InsertQuery for AdminDetails) but HOW do I get the @@IDENTITY from the inserted AdminDetails row into my Locations table?

I've scanned through as many on the posts as I can but can't see anything.

Hope you can help.

Cheers


 
Old September 28th, 2005, 08:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Take a look at scope_identity in the books on line.

Rand
 
Old September 28th, 2005, 09:56 AM
Registered User
 
Join Date: Sep 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Rand,

Perect, that worked a treat, thanks mate.

For the benefit of others I'll detail my solution: -

A CSV file contianing the following fields: -

    LocCode, LocDesc, AdminID, Street, PostCode

(AdminID will be passed as NULL for each record and is included so I can use it in Row Transform)

I have 2 tables: -

Locations
    ID, sequential identity seed
    Code, nvarchar
    Desc, nvarchar
    AdminID, int

AdminDetails
    ID, sequential identity seed
    Street, nvarchar
    PostCode, nvarchar

Locations.AdminID is actualy the AdminDetails.ID generated when inserting into AdminDetails.

Create a Transform Data Task with the Destination as the TillLocations table.
Two lookups: -

Lookup("Insert")
    INSERT INTO AdminNameAddressDetails
                      (StreetDescriptor, Locality, PostCode, IsActive)
    VALUES (?, ?, ?, ?)

Lookup("IDENTITY")
    SELECT IDENT_CURRENT('AdminNameAddressDetails') AS Expr1

(Thanks Rand)

And a single ActivX Script Transformation for ALL fields :-

    Function Main()
        Dim oDummy
        DTSLookups("Insert").Execute DTSSource("Street"), DTSSource("PostCode")

        DTSDestination("AdminID") = DTSLookups("IDENTITY").Execute(DTSSource("AdminID" ))
        DTSDestination("Desc") = DTSSource("Desc")
        DTSDestination("Code") = DTSSource("Code")

        Main = DTSTransformStat_OK
    End Function

Hope this makes sense if not I'll try and explain it a bit better.

Thanks again Rand, I've been trying to solve this one for ages.

Adrian






Similar Threads
Thread Thread Starter Forum Replies Last Post
Scrollbar in row of Datagrid Except Header Row Theone84 ASP.NET 2.0 Professional 0 August 11th, 2008 12:10 AM
To retrieve a row by giving row number prad_a MySQL 1 March 22nd, 2007 11:20 PM
Read a column and Search Row by Row in another col AyatKh Excel VBA 2 January 26th, 2005 12:02 PM
Manage data row by row in datagrid Dragonist Classic ASP Databases 5 July 29th, 2004 04:17 AM
Identity field in the Data Row bmains ADO.NET 2 December 17th, 2003 04:34 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.