Performing corelated subquery in datastage

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
sjordery
Premium Member
Premium Member
Posts: 202
Joined: Thu Jun 08, 2006 5:58 am

Performing corelated subquery in datastage

Post by sjordery »

Hi All,



I have the source data like this

sid,sname,recv_date,no_of_records,ind
----------------------------------------------

1, A, 09-may-2007,800, 1
2, B, 08-may-2007,700, 1
3, A, 08-may-2007,900, 1
4, A, 07-may-2007,600, 0
5, B, 07-may-2007,400, 0
------------------------------------------------

I need to select those records from the source having ind=1
and
an additional column requeried that is no of previous days record(if no record avaliable in previous day check for recent previous)record for same supplier.

my target should be like this


sid,sname,recv_date,no_of_records,ind,prev_day_record
------------------------------------------------------------------
1, A, 09-may-2007, 800, 1, 700
2, B, 08-may-2007, 700, 1, 400
3, A, 08-may-2007, 900, 1, 600
-----------------------------------------------------------------

I may need to process each record from the outer query in the subquery which will compare the date(inner.date<oiter.date) and select the previous day record.
Can anyhbody suggest me how to acheive this in datastage?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The same rules apply in DataStage as in SQL. Can you effect the correlated subquery in your extraction SQL, thereby saving your brain the grief of reinventing a wheel that already exists?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Nisusmage
Premium Member
Premium Member
Posts: 103
Joined: Mon May 07, 2007 1:57 am

Post by Nisusmage »

If you are using ODBC, one thing to note is that ODBC doesn't like grouping and intense SQL statements. The only way to find out if it works, obviously is to test it. If it's a small enough set of data, I say do it.
~The simpliest solutions are always the best~
~Trick is to understand the complexity to implement simplicity~
Post Reply