DELETE MULTIPLE RECORD AFTER DB2 STAGE

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
sam334
Premium Member
Premium Member
Posts: 145
Joined: Mon Aug 26, 2013 7:42 pm

DELETE MULTIPLE RECORD AFTER DB2 STAGE

Post by sam334 »

All , I have a question regarding loading and deleting from a same table.

Initial job design,

File-Tranformer-lookup-Join-DB2Connector.

Data looks like,

ID, NAME,START,END,STATUS
1234,John Smith,01/01/2015,12/31/2016,Pending
1234,John Smith,04/17/2015,12/31/2016,Pending

Now, as first record is the old record, I want to delete this record after loading in DB2 Connector stage. So, I can use a logic that of START of second row is >than previous then delete the record.

Any thoughts how to achieve this, Can we achieve this in a single job.

Thanks.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

How about some details...

This "old" record, it is already there when you load the new one? If so, will there only ever be one old record in the table when you insert a new version? I'm asking because it sounds like you may be able to use the Delete then Insert write mode property:

Delete then insert: Replaces data in an existing table; runs the DELETE statement first, and then runs the INSERT statement.

If that ID is unique, you could key off that.
-craig

"You can never have too many knives" -- Logan Nine Fingers
SURA
Premium Member
Premium Member
Posts: 1229
Joined: Sat Jul 14, 2007 5:16 am
Location: Sydney

Re: DELETE MULTIPLE RECORD AFTER DB2 STAGE

Post by SURA »

sam334 wrote:I want to delete this record after loading in DB2 Connector stage. So, I can use a logic that of START of second row is >than previous then delete the record.
Thanks.
You mean logical delete or that record will be deleted from the table?
Thanks
Ram
----------------------------------
Revealing your ignorance is fine, because you get a chance to learn.
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

There are things you can do before even sending the record to DB2 Connector. You can restrict that record in your job itself. I think if you sort on key and start and take the last record. Pass it through the lookup to get start of the record already there in the data base and if new record has start greater that previous, send it to DB2 in upsert mode else just drop it.


I prefer to keep history in Data warehouse and perform logical delete in there. But all depends on requirement.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
sam334
Premium Member
Premium Member
Posts: 145
Joined: Mon Aug 26, 2013 7:42 pm

Post by sam334 »

Thanks everyone.
@Craig, both the record are in single excel file. So, when we get the first file it has both the records.but we want to store one which has recent start date,
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

OK. Rather than load both / everything and then go back and delete the ones you didn't really want, why not just load the ones you do want and ignore the rest? Seem like that would be a simple matter of making sure the records are sorted appropriately and then using a Remove Duplicates stage... unless I'm missing something.
-craig

"You can never have too many knives" -- Logan Nine Fingers
sam334
Premium Member
Premium Member
Posts: 145
Joined: Mon Aug 26, 2013 7:42 pm

Post by sam334 »

Craig, did that and it worked. I sorted the data and removed duplicates based on the key and it is removing the old one.

Thanks.
Post Reply