dbTalk Databases Forums  

Bisiness Rules in DTS package

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


Discuss Bisiness Rules in DTS package in the microsoft.public.sqlserver.dts forum.



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

Default Bisiness Rules in DTS package - 03-04-2005 , 11:38 AM






I have three tables like this.

Table1:
studentID IsntID FN LN
====== ===== === ===
Primary Key :studentID + IsntID

Table2:
InternalID studentID IsntID FN LN
====== ====== ===== === ===
Primary Key :InternalID
Unique constraint: studentID + IsntID

Table3:
InternalID studentID IsntID TransferDate
====== ====== ===== =========
Primary Key :InternalID
Unique constraint: studentID + IsntID


In my DTS package ,I'd like to check every single row in Table1 to see if
it's in Table3 or not
(based on studentID IsntID),if it exist there ,we simply ignore it and move
to the next record.
if it dosen't exist there then I need to check to see if that one exist in
Table2 or not.

***if It exist in Table2 ,then there are two possibilities:
1) If it's exactly the same ,we ignore it
2) If any field is different ,then the record in Table2 needs to be updated

***If it dosen't exist in Table2 ,then I need to insert it there



Sorry ,if it's a lengthy question ,I appreciate if somebody gives me some
ideas how to do that in my DTS package

Thanks



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

Default Re: Bisiness Rules in DTS package - 03-04-2005 , 11:54 AM






OK

What do you want to do with rows that are in Table 3? Nothing?
If they are not in table 3 you check table 2. If the row is in the
EXACTLY then IGNORE else UPDATE. If it is not there then INSERT


This is easy enough to achieve

The way you explain it suggests you are thinking of a cursor and that is
generally a bad thing


--What is in T1 and not T3
SELECT <col list>
FROM TABLE1 T1 LEFT OUTER JOIN TABLE3 T3
ON T1.StudentID = T3.StudentID
AND T1.IsntID = T3.IsntID
WHERE T3.StudentID IS NULL
AND T3.IsntID IS NULL

--For your Updates of T2 I would probably do a Blanket UPDATE across all
rows that are already there anyway as it would more than likely cost you
more to check each attribute
--Use this as an input to your second query which uses the same idea to
do the inserts into T2

Do the updates before the Inserts otherwise you will end up doing more
UPDATEs than necessary.

Make sense?


Allan


"RayAll" <RayAll (AT) microsft (DOT) com> wrote


Quote:
I have three tables like this.

Table1:
studentID IsntID FN LN
====== ===== === ===
Primary Key :studentID + IsntID

Table2:
InternalID studentID IsntID FN LN
====== ====== ===== === ===
Primary Key :InternalID
Unique constraint: studentID + IsntID

Table3:
InternalID studentID IsntID TransferDate
====== ====== ===== =========
Primary Key :InternalID
Unique constraint: studentID + IsntID


In my DTS package ,I'd like to check every single row in Table1 to see if
it's in Table3 or not
(based on studentID IsntID),if it exist there ,we simply ignore it and move
to the next record.
if it dosen't exist there then I need to check to see if that one exist in
Table2 or not.

***if It exist in Table2 ,then there are two possibilities:
1) If it's exactly the same ,we ignore it
2) If any field is different ,then the record in Table2 needs to be updated

***If it dosen't exist in Table2 ,then I need to insert it there



Sorry ,if it's a lengthy question ,I appreciate if somebody gives me some
ideas how to do that in my DTS package

Thanks


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

Default Re: Bisiness Rules in DTS package - 03-04-2005 , 12:41 PM



Quote:
What do you want to do with rows that are in Table 3? Nothing?
-Table3 only contains kind of history,I do nothing with it except a simple
comparing.

As far I underestood ,in your suggession,

Step 1) we get a list of records which is in T1 and don't exist in
T3(history table) => output: bunch of records [I underestood this part]
Step 2) update all T2 records with the output of Step1

Question1: How can I update all records in T2 using the output of step1
Question2: There might be some records in Step1 output that don't exist
in T2-I need to insert them into T2,there is n update for these,How can I
acheieve this?

Step3) Insert the new records into T2 [I didn't underestand this section]


Question3:What task should I use for doing this in a DTS package?


Thanks very much for your help.
Roy


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

Quote:
OK

What do you want to do with rows that are in Table 3? Nothing?
If they are not in table 3 you check table 2. If the row is in the
EXACTLY then IGNORE else UPDATE. If it is not there then INSERT


This is easy enough to achieve

The way you explain it suggests you are thinking of a cursor and that is
generally a bad thing


--What is in T1 and not T3
SELECT <col list
FROM TABLE1 T1 LEFT OUTER JOIN TABLE3 T3
ON T1.StudentID = T3.StudentID
AND T1.IsntID = T3.IsntID
WHERE T3.StudentID IS NULL
AND T3.IsntID IS NULL

--For your Updates of T2 I would probably do a Blanket UPDATE across all
rows that are already there anyway as it would more than likely cost you
more to check each attribute
--Use this as an input to your second query which uses the same idea to do
the inserts into T2

Do the updates before the Inserts otherwise you will end up doing more
UPDATEs than necessary.

Make sense?


Allan


"RayAll" <RayAll (AT) microsft (DOT) com> wrote


I have three tables like this.

Table1:
studentID IsntID FN LN
====== ===== === ===
Primary Key :studentID + IsntID

Table2:
InternalID studentID IsntID FN LN
====== ====== ===== === ===
Primary Key :InternalID
Unique constraint: studentID + IsntID

Table3:
InternalID studentID IsntID TransferDate
====== ====== ===== =========
Primary Key :InternalID
Unique constraint: studentID + IsntID


In my DTS package ,I'd like to check every single row in Table1 to see if
it's in Table3 or not
(based on studentID IsntID),if it exist there ,we simply ignore it and
move
to the next record.
if it dosen't exist there then I need to check to see if that one exist
in
Table2 or not.

***if It exist in Table2 ,then there are two possibilities:
1) If it's exactly the same ,we ignore it
2) If any field is different ,then the record in Table2 needs to be
updated

***If it dosen't exist in Table2 ,then I need to insert it there



Sorry ,if it's a lengthy question ,I appreciate if somebody gives me some
ideas how to do that in my DTS package

Thanks




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

Default Re: Bisiness Rules in DTS package - 03-04-2005 , 02:26 PM



You have two tasks

1 = DataPump task to do the inserts. This is the rows that are NOT in
T3 and also NOT in T2
2 = ExecuteSQL Task to do the UPDATE

Allan

"RayAll" <RayAll (AT) microsft (DOT) com> wrote


Quote:
What do you want to do with rows that are in Table 3? Nothing?

-Table3 only contains kind of history,I do nothing with it except a simple
comparing.

As far I underestood ,in your suggession,

Step 1) we get a list of records which is in T1 and don't exist in
T3(history table) => output: bunch of records [I underestood this part]
Step 2) update all T2 records with the output of Step1

Question1: How can I update all records in T2 using the output of step1
Question2: There might be some records in Step1 output that don't exist
in T2-I need to insert them into T2,there is n update for these,How can I
acheieve this?

Step3) Insert the new records into T2 [I didn't underestand this section]


Question3:What task should I use for doing this in a DTS package?


Thanks very much for your help.
Roy


"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote in message
news:uNKDZKOIFHA.580 (AT) TK2MSFTNGP15 (DOT) phx.gbl...
OK

What do you want to do with rows that are in Table 3? Nothing?
If they are not in table 3 you check table 2. If the row is in the
EXACTLY then IGNORE else UPDATE. If it is not there then INSERT


This is easy enough to achieve

The way you explain it suggests you are thinking of a cursor and that is
generally a bad thing


--What is in T1 and not T3
SELECT <col list
FROM TABLE1 T1 LEFT OUTER JOIN TABLE3 T3
ON T1.StudentID = T3.StudentID
AND T1.IsntID = T3.IsntID
WHERE T3.StudentID IS NULL
AND T3.IsntID IS NULL

--For your Updates of T2 I would probably do a Blanket UPDATE across all
rows that are already there anyway as it would more than likely cost you
more to check each attribute
--Use this as an input to your second query which uses the same idea to do
the inserts into T2

Do the updates before the Inserts otherwise you will end up doing more
UPDATEs than necessary.

Make sense?


Allan


"RayAll" <RayAll (AT) microsft (DOT) com> wrote


I have three tables like this.

Table1:
studentID IsntID FN LN
====== ===== === ===
Primary Key :studentID + IsntID

Table2:
InternalID studentID IsntID FN LN
====== ====== ===== === ===
Primary Key :InternalID
Unique constraint: studentID + IsntID

Table3:
InternalID studentID IsntID TransferDate
====== ====== ===== =========
Primary Key :InternalID
Unique constraint: studentID + IsntID


In my DTS package ,I'd like to check every single row in Table1 to see if
it's in Table3 or not
(based on studentID IsntID),if it exist there ,we simply ignore it and
move
to the next record.
if it dosen't exist there then I need to check to see if that one exist
in
Table2 or not.

***if It exist in Table2 ,then there are two possibilities:
1) If it's exactly the same ,we ignore it
2) If any field is different ,then the record in Table2 needs to be
updated

***If it dosen't exist in Table2 ,then I need to insert it there



Sorry ,if it's a lengthy question ,I appreciate if somebody gives me some
ideas how to do that in my DTS package

Thanks



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

Default Re: Bisiness Rules in DTS package - 03-04-2005 , 03:10 PM



Are these two tasks sequential or both could be done at the same time on T1?

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

Quote:
You have two tasks

1 = DataPump task to do the inserts. This is the rows that are NOT in T3
and also NOT in T2
2 = ExecuteSQL Task to do the UPDATE

Allan

"RayAll" <RayAll (AT) microsft (DOT) com> wrote


What do you want to do with rows that are in Table 3? Nothing?

-Table3 only contains kind of history,I do nothing with it except a
simple
comparing.

As far I underestood ,in your suggession,

Step 1) we get a list of records which is in T1 and don't exist in
T3(history table) => output: bunch of records [I underestood this part]
Step 2) update all T2 records with the output of Step1

Question1: How can I update all records in T2 using the output of
step1
Question2: There might be some records in Step1 output that don't
exist
in T2-I need to insert them into T2,there is n update for these,How can I
acheieve this?

Step3) Insert the new records into T2 [I didn't underestand this section]


Question3:What task should I use for doing this in a DTS package?


Thanks very much for your help.
Roy


"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote in message
news:uNKDZKOIFHA.580 (AT) TK2MSFTNGP15 (DOT) phx.gbl...
OK

What do you want to do with rows that are in Table 3? Nothing?
If they are not in table 3 you check table 2. If the row is in the
EXACTLY then IGNORE else UPDATE. If it is not there then INSERT


This is easy enough to achieve

The way you explain it suggests you are thinking of a cursor and that
is
generally a bad thing


--What is in T1 and not T3
SELECT <col list
FROM TABLE1 T1 LEFT OUTER JOIN TABLE3 T3
ON T1.StudentID = T3.StudentID
AND T1.IsntID = T3.IsntID
WHERE T3.StudentID IS NULL
AND T3.IsntID IS NULL

--For your Updates of T2 I would probably do a Blanket UPDATE across
all
rows that are already there anyway as it would more than likely cost
you
more to check each attribute
--Use this as an input to your second query which uses the same idea to
do
the inserts into T2

Do the updates before the Inserts otherwise you will end up doing more
UPDATEs than necessary.

Make sense?


Allan


"RayAll" <RayAll (AT) microsft (DOT) com> wrote in message
news:RayAll (AT) microsft (DOT) com:

I have three tables like this.

Table1:
studentID IsntID FN LN
====== ===== === ===
Primary Key :studentID + IsntID

Table2:
InternalID studentID IsntID FN LN
====== ====== ===== === ===
Primary Key :InternalID
Unique constraint: studentID + IsntID

Table3:
InternalID studentID IsntID TransferDate
====== ====== ===== =========
Primary Key :InternalID
Unique constraint: studentID + IsntID


In my DTS package ,I'd like to check every single row in Table1 to see
if
it's in Table3 or not
(based on studentID IsntID),if it exist there ,we simply ignore it
and
move
to the next record.
if it dosen't exist there then I need to check to see if that one
exist
in
Table2 or not.

***if It exist in Table2 ,then there are two possibilities:
1) If it's exactly the same ,we ignore it
2) If any field is different ,then the record in Table2 needs to be
updated

***If it dosen't exist in Table2 ,then I need to insert it there



Sorry ,if it's a lengthy question ,I appreciate if somebody gives me
some
ideas how to do that in my DTS package

Thanks





Reply With Quote
  #6  
Old   
RayAll
 
Posts: n/a

Default Re: Bisiness Rules in DTS package - 03-04-2005 , 03:12 PM



Thanks for your nice reply,I think tht's going to work ,but a quick
question:

In Table1 there is also a status field which I'd like to set to show what
has happened to that row :

For instance :
If the row has been ignored I'd like it to be 1,if it has been inserted into
Table2 ,I'd like it to be 2 and if It has been updated I'd like it to be 3


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

Quote:
You have two tasks

1 = DataPump task to do the inserts. This is the rows that are NOT in T3
and also NOT in T2
2 = ExecuteSQL Task to do the UPDATE

Allan

"RayAll" <RayAll (AT) microsft (DOT) com> wrote


What do you want to do with rows that are in Table 3? Nothing?

-Table3 only contains kind of history,I do nothing with it except a
simple
comparing.

As far I underestood ,in your suggession,

Step 1) we get a list of records which is in T1 and don't exist in
T3(history table) => output: bunch of records [I underestood this part]
Step 2) update all T2 records with the output of Step1

Question1: How can I update all records in T2 using the output of
step1
Question2: There might be some records in Step1 output that don't
exist
in T2-I need to insert them into T2,there is n update for these,How can I
acheieve this?

Step3) Insert the new records into T2 [I didn't underestand this section]


Question3:What task should I use for doing this in a DTS package?


Thanks very much for your help.
Roy


"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote in message
news:uNKDZKOIFHA.580 (AT) TK2MSFTNGP15 (DOT) phx.gbl...
OK

What do you want to do with rows that are in Table 3? Nothing?
If they are not in table 3 you check table 2. If the row is in the
EXACTLY then IGNORE else UPDATE. If it is not there then INSERT


This is easy enough to achieve

The way you explain it suggests you are thinking of a cursor and that
is
generally a bad thing


--What is in T1 and not T3
SELECT <col list
FROM TABLE1 T1 LEFT OUTER JOIN TABLE3 T3
ON T1.StudentID = T3.StudentID
AND T1.IsntID = T3.IsntID
WHERE T3.StudentID IS NULL
AND T3.IsntID IS NULL

--For your Updates of T2 I would probably do a Blanket UPDATE across
all
rows that are already there anyway as it would more than likely cost
you
more to check each attribute
--Use this as an input to your second query which uses the same idea to
do
the inserts into T2

Do the updates before the Inserts otherwise you will end up doing more
UPDATEs than necessary.

Make sense?


Allan


"RayAll" <RayAll (AT) microsft (DOT) com> wrote in message
news:RayAll (AT) microsft (DOT) com:

I have three tables like this.

Table1:
studentID IsntID FN LN
====== ===== === ===
Primary Key :studentID + IsntID

Table2:
InternalID studentID IsntID FN LN
====== ====== ===== === ===
Primary Key :InternalID
Unique constraint: studentID + IsntID

Table3:
InternalID studentID IsntID TransferDate
====== ====== ===== =========
Primary Key :InternalID
Unique constraint: studentID + IsntID


In my DTS package ,I'd like to check every single row in Table1 to see
if
it's in Table3 or not
(based on studentID IsntID),if it exist there ,we simply ignore it
and
move
to the next record.
if it dosen't exist there then I need to check to see if that one
exist
in
Table2 or not.

***if It exist in Table2 ,then there are two possibilities:
1) If it's exactly the same ,we ignore it
2) If any field is different ,then the record in Table2 needs to be
updated

***If it dosen't exist in Table2 ,then I need to insert it there



Sorry ,if it's a lengthy question ,I appreciate if somebody gives me
some
ideas how to do that in my DTS package

Thanks





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

Default Re: Bisiness Rules in DTS package - 03-04-2005 , 03:24 PM



Then you do your UPDATEs based on the same criteria as you use to decide
what happens to the other rows.

In your INSERTS you insert a flag value
In your UPDATEs you update the flag value.
You then update again those values that were untouched.

"RayAll" <RayAll (AT) microsft (DOT) com> wrote


Quote:
Thanks for your nice reply,I think tht's going to work ,but a quick
question:

In Table1 there is also a status field which I'd like to set to show what
has happened to that row :

For instance :
If the row has been ignored I'd like it to be 1,if it has been inserted into
Table2 ,I'd like it to be 2 and if It has been updated I'd like it to be 3


"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote in message
news:%23mUlSfPIFHA.1996 (AT) TK2MSFTNGP12 (DOT) phx.gbl...
You have two tasks

1 = DataPump task to do the inserts. This is the rows that are NOT in T3
and also NOT in T2
2 = ExecuteSQL Task to do the UPDATE

Allan

"RayAll" <RayAll (AT) microsft (DOT) com> wrote


What do you want to do with rows that are in Table 3? Nothing?

-Table3 only contains kind of history,I do nothing with it except a
simple
comparing.

As far I underestood ,in your suggession,

Step 1) we get a list of records which is in T1 and don't exist in
T3(history table) => output: bunch of records [I underestood this part]
Step 2) update all T2 records with the output of Step1

Question1: How can I update all records in T2 using the output of
step1
Question2: There might be some records in Step1 output that don't
exist
in T2-I need to insert them into T2,there is n update for these,How can I
acheieve this?

Step3) Insert the new records into T2 [I didn't underestand this section]


Question3:What task should I use for doing this in a DTS package?


Thanks very much for your help.
Roy


"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote in message
news:uNKDZKOIFHA.580 (AT) TK2MSFTNGP15 (DOT) phx.gbl...
OK

What do you want to do with rows that are in Table 3? Nothing?
If they are not in table 3 you check table 2. If the row is in the
EXACTLY then IGNORE else UPDATE. If it is not there then INSERT


This is easy enough to achieve

The way you explain it suggests you are thinking of a cursor and that
is
generally a bad thing


--What is in T1 and not T3
SELECT <col list
FROM TABLE1 T1 LEFT OUTER JOIN TABLE3 T3
ON T1.StudentID = T3.StudentID
AND T1.IsntID = T3.IsntID
WHERE T3.StudentID IS NULL
AND T3.IsntID IS NULL

--For your Updates of T2 I would probably do a Blanket UPDATE across
all
rows that are already there anyway as it would more than likely cost
you
more to check each attribute
--Use this as an input to your second query which uses the same idea to
do
the inserts into T2

Do the updates before the Inserts otherwise you will end up doing more
UPDATEs than necessary.

Make sense?


Allan


"RayAll" <RayAll (AT) microsft (DOT) com> wrote in message
news:RayAll (AT) microsft (DOT) com:

I have three tables like this.

Table1:
studentID IsntID FN LN
====== ===== === ===
Primary Key :studentID + IsntID

Table2:
InternalID studentID IsntID FN LN
====== ====== ===== === ===
Primary Key :InternalID
Unique constraint: studentID + IsntID

Table3:
InternalID studentID IsntID TransferDate
====== ====== ===== =========
Primary Key :InternalID
Unique constraint: studentID + IsntID


In my DTS package ,I'd like to check every single row in Table1 to see
if
it's in Table3 or not
(based on studentID IsntID),if it exist there ,we simply ignore it
and
move
to the next record.
if it dosen't exist there then I need to check to see if that one
exist
in
Table2 or not.

***if It exist in Table2 ,then there are two possibilities:
1) If it's exactly the same ,we ignore it
2) If any field is different ,then the record in Table2 needs to be
updated

***If it dosen't exist in Table2 ,then I need to insert it there



Sorry ,if it's a lengthy question ,I appreciate if somebody gives me
some
ideas how to do that in my DTS package

Thanks




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.