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 June 15th, 2006, 03:32 PM
Authorized User
 
Join Date: Oct 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default DTS return table ID

Hi All
I have the task of taking a long ASCII string in a flat file and importing it to SQL server.

I have to insert into several tables, but all tables but 1 require the table ID column of the "main" table, if you will. Example:

CREATE TABLE T_MAIN
(
    T_ID BIGINT IDENTITY(1,1),
    T_DATA1 VARCHAR(50)
)
CREATE TABLE T_SATELLITE
(
    TSAT_ID BIGINT IDENTITY(1,1),
    T_ID BIGINT NOT NULL,
    TSAT_DATA1 VARCHAR(70)
)
T_MAIN.T_ID has a one-to-many relationship with T_SATELLITE.T_ID.

When I do the insert into T_MAIN, I want to get the value that was automatically put into T_ID and use it in my T_SATELLITE data import task.

Any help offered is very much appreciated!

Thanks!

"A spirit with a vision is a dream with a mission"
__________________
\"A spirit with a vision is a dream with a mission\"
 
Old June 16th, 2006, 05:50 AM
Authorized User
 
Join Date: Oct 2004
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

As per your information, i can suggest you this idea.

In SQL Server, there is a global variable @@identity which can return the current id generated.

Process of Execution should be:

              1. Insert into T_Main values('some long data')
              2. Select @@identity

Above statements will execute the insert statement and give an output of last generated identity. U can use this for your further process.



A.D.Ramkumar
 
Old November 9th, 2006, 12:15 PM
Registered User
 
Join Date: Sep 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In DTS you can't use @@ACCEPT so what I did was write a Lookup that did -->

SELECT IDENT_CURRENT('TABLENAME') AS Expr1

You must call this lookup immediately after you have inserted into your satellite table to return the last ID inserted.

Hope that helps.

Adrian






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to return the ID through a dataset? chobo2 C# 2008 aka C# 3.0 10 June 25th, 2008 07:56 PM
ADD DB RECORD/ RETURN ID Huascar82 Classic ASP Databases 1 October 1st, 2007 11:55 PM
Update one table to another table using DTS in SQL Printmaker SQL Language 0 July 24th, 2007 07:17 AM
update table with an ID Num from different table scoobie PHP How-To 12 January 25th, 2005 12:28 PM
could i join function(return table) with a table alyeng2000 SQL Server 2000 6 September 30th, 2004 07:23 AM





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