dbTalk Databases Forums  

LookUp Query in DTS cannot read the destination table

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


Discuss LookUp Query in DTS cannot read the destination table in the microsoft.public.sqlserver.dts forum.



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

Default LookUp Query in DTS cannot read the destination table - 11-19-2003 , 05:26 AM






Hi all,

I have created a DTS package to transfer data from a some tables in a Access database to SQL server.
I use a transform data task and specifiy a source and destination table and use a activeX script perform the source/destination mapping.
Because the data source is a union of some tables, some of the value violate the primary key contrainst of the destination table. To overcome this, I have created a lookup query in the transform data task to check whether the primary is already existed, if yes, then skip the current record, otherwise, insert in to the destination table.

But I find that if the source table contain 2 records with the same primary key, the lookup query also return false for the checking and so thuse cause the package fail due to the violation of primary key.
What I want to ask is if the lookup query can read the data just added to the destination table in the same batch ? Or the lookup query only can read committed data even the uncommitted data is within the same session ?

Thank in advance.

Regards,
ong

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

Default Re: LookUp Query in DTS cannot read the destination table - 11-19-2003 , 06:07 AM






I would sort the data out in the source first

UNION will remove duplicates that are duplicates due to the Unioning.

DISTINCT will make a row distinct.

How can you have duplicate Key values ?

--

----------------------------
Allan Mitchell (Microsoft SQL Server MVP)
MCSE,MCDBA
www.SQLDTS.com
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org



"ong" <anonymous (AT) discussions (DOT) microsoft.com> wrote

Quote:
Hi all,

I have created a DTS package to transfer data from a some tables in a
Access database to SQL server.
I use a transform data task and specifiy a source and destination table
and use a activeX script perform the source/destination mapping.
Because the data source is a union of some tables, some of the value
violate the primary key contrainst of the destination table. To overcome
this, I have created a lookup query in the transform data task to check
whether the primary is already existed, if yes, then skip the current
record, otherwise, insert in to the destination table.
Quote:
But I find that if the source table contain 2 records with the same
primary key, the lookup query also return false for the checking and so
thuse cause the package fail due to the violation of primary key.
Quote:
What I want to ask is if the lookup query can read the data just added to
the destination table in the same batch ? Or the lookup query only can read
committed data even the uncommitted data is within the same session ?
Quote:
Thank in advance.

Regards,
ong



Reply With Quote
  #3  
Old   
ong
 
Posts: n/a

Default Re: LookUp Query in DTS cannot read the destination table - 11-19-2003 , 08:31 PM



Hi Allan,

The source do have some duplicate records because the design of Access application is quite a little bit different from the design of the new SQL server application
There are 3 tables (each table serve for different purpose) storing the records of some kind of contact list in the Access application, some of the records exist in all the 3 tables, for example, all the tables contain a "microsoft" contact information, and all tables use the "microsoft" as the key value
Therefore, when I transform records from Access to SQL server, the duplicate key still exist.
I have try to use Union and distinct, but the only duplicate value is just the key value, the other column value is different
for example, there is a address column, and 1 table contain "USA" as address, 1 table contain "U.S.A." as address, the 1 table contain "US" as address. Therefore, both union and distinct cannot work
I finally use a lookup query to achieve the goal, but it fail and alway say that the table contain no row due to the transfer data task not yet finish


----- Allan Mitchell wrote: ----

I would sort the data out in the source firs

UNION will remove duplicates that are duplicates due to the Unioning

DISTINCT will make a row distinct

How can you have duplicate Key values

--

---------------------------
Allan Mitchell (Microsoft SQL Server MVP
MCSE,MCDB
www.SQLDTS.co
I support PASS - the definitive, global communit
for SQL Server professionals - http://www.sqlpass.or



"ong" <anonymous (AT) discussions (DOT) microsoft.com> wrote in messag
news:C26E3721-8548-4A8B-BBCF-D0EA24E62EBE (AT) microsoft (DOT) com..
Quote:
Hi all
I have created a DTS package to transfer data from a some tables in
Access database to SQL server
I use a transform data task and specifiy a source and destination tabl
and use a activeX script perform the source/destination mapping
Because the data source is a union of some tables, some of the valu
violate the primary key contrainst of the destination table. To overcom
this, I have created a lookup query in the transform data task to chec
whether the primary is already existed, if yes, then skip the curren
record, otherwise, insert in to the destination table
Quote:
But I find that if the source table contain 2 records with the sam
primary key, the lookup query also return false for the checking and s
thuse cause the package fail due to the violation of primary key
Quote:
What I want to ask is if the lookup query can read the data just added t
the destination table in the same batch ? Or the lookup query only can rea
committed data even the uncommitted data is within the same session
Quote:
Thank in advance
Regards
on




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

Default Re: LookUp Query in DTS cannot read the destination table - 11-20-2003 , 12:18 AM



UURRGGGHH. OK Ideally you would have a deduping program to do this. Yukon
is gonna light your fire for this. For your Lookup Query assign a different
connection object not the one you are using in the transformation task.

--
--

Allan Mitchell (Microsoft SQL Server MVP)
MCSE,MCDBA
www.SQLDTS.com
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org

"ong" <on_g (AT) sinatown (DOT) com> wrote

Quote:
Hi Allan,

The source do have some duplicate records because the design of Access
application is quite a little bit different from the design of the new SQL
server application.
Quote:
There are 3 tables (each table serve for different purpose) storing the
records of some kind of contact list in the Access application, some of the
records exist in all the 3 tables, for example, all the tables contain a
"microsoft" contact information, and all tables use the "microsoft" as the
key value.
Quote:
Therefore, when I transform records from Access to SQL server, the
duplicate key still exist..
I have try to use Union and distinct, but the only duplicate value is just
the key value, the other column value is different.
for example, there is a address column, and 1 table contain "USA" as
address, 1 table contain "U.S.A." as address, the 1 table contain "US" as
address. Therefore, both union and distinct cannot work.
Quote:
I finally use a lookup query to achieve the goal, but it fail and alway
say that the table contain no row due to the transfer data task not yet
finish.
Quote:


----- Allan Mitchell wrote: -----

I would sort the data out in the source first

UNION will remove duplicates that are duplicates due to the Unioning.

DISTINCT will make a row distinct.

How can you have duplicate Key values ?

--

----------------------------
Allan Mitchell (Microsoft SQL Server MVP)
MCSE,MCDBA
www.SQLDTS.com
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org



"ong" <anonymous (AT) discussions (DOT) microsoft.com> wrote in message
news:C26E3721-8548-4A8B-BBCF-D0EA24E62EBE (AT) microsoft (DOT) com...
Hi all,
I have created a DTS package to transfer data from a some tables
in a
Access database to SQL server.
I use a transform data task and specifiy a source and destination
table
and use a activeX script perform the source/destination mapping.
Because the data source is a union of some tables, some of the
value
violate the primary key contrainst of the destination table. To
overcome
this, I have created a lookup query in the transform data task to
check
whether the primary is already existed, if yes, then skip the current
record, otherwise, insert in to the destination table.
But I find that if the source table contain 2 records with the
same
primary key, the lookup query also return false for the checking and
so
thuse cause the package fail due to the violation of primary key.
What I want to ask is if the lookup query can read the data just
added to
the destination table in the same batch ? Or the lookup query only
can read
committed data even the uncommitted data is within the same session ?
Thank in advance.
Regards,
ong






Reply With Quote
  #5  
Old   
ong
 
Posts: n/a

Default Re: LookUp Query in DTS cannot read the destination table - 11-20-2003 , 09:26 PM



Hi Allan

Thank for your reply
I have created a different connection to the Lookup Query, but it seems the key constraint violation still occur

Maybe I explain what I gonna to do in more details
I have 3 tables in Access to store some contact information of my client. Now I want to transfer and combine all the data from the 3 Access table to 1 SQL Server table. Since some records is duplicated after union the Access tables, they have the same primary key but different column values, for example, the "microsoft" contact information. Therefore , when I run my DTS package, it will fail due to the key constraint violation error
So I created a LookUp Query in the transformation task, the reason is I supposed the query can check the destination table whether the current record already exists in the table, if yes, then skip it, otherwise, add it
For example, when the transformation task first read the "microsoft" record, then it first check for the destination table to see if the records exist, if no, it return "record not find", then the task insert it to the destination table. And the task continue, when the second time the task read again the other "microsoft" record, it perform a lookup query to the destination table and should return "record find",then the task skip the record
Now the problem is when the DTS package run, no matter the "microsoft" record is already inserted to the table from the first time the task read the record, the lookup query alway return "record not find" when the task read the "microsoft" record second time
Is it related to the transaction problem ? Since the task still running and not yet commit the changes, so the lookup query cannot read the "dirty" data

Thank in advanc
on

----- Allan Mitchell wrote: ----

UURRGGGHH. OK Ideally you would have a deduping program to do this. Yuko
is gonna light your fire for this. For your Lookup Query assign a differen
connection object not the one you are using in the transformation task

--
-

Allan Mitchell (Microsoft SQL Server MVP
MCSE,MCDB
www.SQLDTS.co
I support PASS - the definitive, global communit
for SQL Server professionals - http://www.sqlpass.or

"ong" <on_g (AT) sinatown (DOT) com> wrote in messag
news:AEFFB477-DC7F-47F8-BB8A-CE4ED5035DD3 (AT) microsoft (DOT) com..
Quote:
Hi Allan
The source do have some duplicate records because the design of Acces
application is quite a little bit different from the design of the new SQ
server application
Quote:
There are 3 tables (each table serve for different purpose) storing th
records of some kind of contact list in the Access application, some of th
records exist in all the 3 tables, for example, all the tables contain
"microsoft" contact information, and all tables use the "microsoft" as th
key value
Quote:
Therefore, when I transform records from Access to SQL server, th
duplicate key still exist.
I have try to use Union and distinct, but the only duplicate value is jus
the key value, the other column value is different
for example, there is a address column, and 1 table contain "USA" a
address, 1 table contain "U.S.A." as address, the 1 table contain "US" a
address. Therefore, both union and distinct cannot work
Quote:
I finally use a lookup query to achieve the goal, but it fail and alwa
say that the table contain no row due to the transfer data task not ye
finish
Quote:
----- Allan Mitchell wrote: ----
I would sort the data out in the source firs
UNION will remove duplicates that are duplicates due to the Unioning
DISTINCT will make a row distinct
How can you have duplicate Key values
--
---------------------------
Allan Mitchell (Microsoft SQL Server MVP
MCSE,MCDB
www.SQLDTS.co
I support PASS - the definitive, global communit
for SQL Server professionals - http://www.sqlpass.or
"ong" <anonymous (AT) discussions (DOT) microsoft.com> wrote in message
news:C26E3721-8548-4A8B-BBCF-D0EA24E62EBE (AT) microsoft (DOT) com...
Hi all,
I have created a DTS package to transfer data from a some tables
in a
Access database to SQL server.
I use a transform data task and specifiy a source and destination
table
and use a activeX script perform the source/destination mapping.
Because the data source is a union of some tables, some of the
value
violate the primary key contrainst of the destination table. To
overcome
this, I have created a lookup query in the transform data task to
check
whether the primary is already existed, if yes, then skip the current
record, otherwise, insert in to the destination table.
But I find that if the source table contain 2 records with the
same
primary key, the lookup query also return false for the checking and
so
thuse cause the package fail due to the violation of primary key.
What I want to ask is if the lookup query can read the data just
added to
the destination table in the same batch ? Or the lookup query only
can read
committed data even the uncommitted data is within the same session ?
Thank in advance.
Regards,
ong


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

Default Re: LookUp Query in DTS cannot read the destination table - 11-21-2003 , 01:20 AM



OK

Scrubbing time. Do you care which "Microsoft" row gets inserted ? We need
to dedupe these rows. Insert them into SQL Server into a table that has the
sme PK as before. Do not use a PK but use an index with IGNORE_DUP_KEY
i.e

CREATE TABLE Foo(ABC int)
CREATE UNIQUE INDEX idx_Filter_Dups ON Foo(ABC) WITH IGNORE_DUP_KEY
INSERT Foo VALUES(1)
INSERT Foo VALUES(1)


(1 row(s) affected)

Server: Msg 3604, Level 16, State 1, Line 2
Duplicate key was ignored.


select * from Foo

ABC
-----------
1

(1 row(s) affected)


Or you could pump each of your 3 tables into the same table but add an
INDENTITY() column. You would then take over using DTS only those records
that had the lowest IDENTITY() column value for each of your previous PK
values i.e.

CREATE TABLE PK(Col1 INT IDENTITY(1,1),colYourPK
varchar(50)....................)

--Do your insert into this

SELECT colYourPK................................
FROM PK T1 WHERE Col1 = (SELECT MIN(Col1) FROM PK T2 WHERE T2.ColYourPK =
T1.ColYourPK)





--
--

Allan Mitchell (Microsoft SQL Server MVP)
MCSE,MCDBA
www.SQLDTS.com
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org

"ong" <on_g (AT) sinatown (DOT) com> wrote

Quote:
Hi Allan,

Thank for your reply.
I have created a different connection to the Lookup Query, but it seems
the key constraint violation still occur.

Maybe I explain what I gonna to do in more details.
I have 3 tables in Access to store some contact information of my client.
Now I want to transfer and combine all the data from the 3 Access table to 1
SQL Server table. Since some records is duplicated after union the Access
tables, they have the same primary key but different column values, for
example, the "microsoft" contact information. Therefore , when I run my DTS
package, it will fail due to the key constraint violation error.
Quote:
So I created a LookUp Query in the transformation task, the reason is I
supposed the query can check the destination table whether the current
record already exists in the table, if yes, then skip it, otherwise, add it.
Quote:
For example, when the transformation task first read the "microsoft"
record, then it first check for the destination table to see if the records
exist, if no, it return "record not find", then the task insert it to the
destination table. And the task continue, when the second time the task read
again the other "microsoft" record, it perform a lookup query to the
destination table and should return "record find",then the task skip the
record.
Quote:
Now the problem is when the DTS package run, no matter the "microsoft"
record is already inserted to the table from the first time the task read
the record, the lookup query alway return "record not find" when the task
read the "microsoft" record second time.
Quote:
Is it related to the transaction problem ? Since the task still running
and not yet commit the changes, so the lookup query cannot read the "dirty"
data ?
Quote:
Thank in advance
ong

----- Allan Mitchell wrote: -----

UURRGGGHH. OK Ideally you would have a deduping program to do this.
Yukon
is gonna light your fire for this. For your Lookup Query assign a
different
connection object not the one you are using in the transformation
task.

--
--

Allan Mitchell (Microsoft SQL Server MVP)
MCSE,MCDBA
www.SQLDTS.com
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org

"ong" <on_g (AT) sinatown (DOT) com> wrote in message
news:AEFFB477-DC7F-47F8-BB8A-CE4ED5035DD3 (AT) microsoft (DOT) com...
Hi Allan,
The source do have some duplicate records because the design of
Access
application is quite a little bit different from the design of the
new SQL
server application.
There are 3 tables (each table serve for different purpose) storing
the
records of some kind of contact list in the Access application, some
of the
records exist in all the 3 tables, for example, all the tables
contain a
"microsoft" contact information, and all tables use the "microsoft"
as the
key value.
Therefore, when I transform records from Access to SQL server, the
duplicate key still exist..
I have try to use Union and distinct, but the only duplicate value
is just
the key value, the other column value is different.
for example, there is a address column, and 1 table contain "USA"
as
address, 1 table contain "U.S.A." as address, the 1 table contain
"US" as
address. Therefore, both union and distinct cannot work.
I finally use a lookup query to achieve the goal, but it fail and
alway
say that the table contain no row due to the transfer data task not
yet
finish.
----- Allan Mitchell wrote: -----
I would sort the data out in the source first
UNION will remove duplicates that are duplicates due to the
Unioning.
DISTINCT will make a row distinct.
How can you have duplicate Key values ?
--
----------------------------
Allan Mitchell (Microsoft SQL Server MVP)
MCSE,MCDBA
www.SQLDTS.com
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org
"ong" <anonymous (AT) discussions (DOT) microsoft.com> wrote in
message
news:C26E3721-8548-4A8B-BBCF-D0EA24E62EBE (AT) microsoft (DOT) com...
Hi all,
I have created a DTS package to transfer data from a some tables
in a
Access database to SQL server.
I use a transform data task and specifiy a source and destination
table
and use a activeX script perform the source/destination mappin
g.
Because the data source is a union of some tables, some of the
value
violate the primary key contrainst of the destination table.
To
overcome
this, I have created a lookup query in the transform data task
to
check
whether the primary is already existed, if yes, then skip the
current
record, otherwise, insert in to the destination table.
But I find that if the source table contain 2 records with the
same
primary key, the lookup query also return false for the
checking and
so
thuse cause the package fail due to the violation of primary
key.
What I want to ask is if the lookup query can read the data just
added to
the destination table in the same batch ? Or the lookup query
only
can read
committed data even the uncommitted data is within the same
session ?
Thank in advance.
Regards,
ong




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.