Dynamically generate where clause-Urgent

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
bakul
Participant
Posts: 60
Joined: Wed Nov 10, 2004 2:12 am

Dynamically generate where clause-Urgent

Post by bakul »

I have a situation where I have to retrieve values for the same fields from a DB2 database every time but the where condition depends on the input data.
Is there any way to dynamically change the where clause in a DB2/UDB or ODBC stage used for lookup?

Thanks and regards,
Bakul
:roll:
vigneshra
Participant
Posts: 86
Joined: Wed Jun 09, 2004 6:07 am
Location: Chennai

Post by vigneshra »

Your question is not very clear in the first place. But as far I understood, I tell you something which you have to check if useful or not. You generate whatever the where condition you want to generate from the input data in a seperate job and write it into an OS file. Then in the second job, you read the file and assign it as a parameter to the job. You include that parameter in the userdefined query in the extraction DB2 plugin. I think this will serve your need.

Vignesh.
Amos.Rosmarin
Premium Member
Premium Member
Posts: 385
Joined: Tue Oct 07, 2003 4:55 am

Post by Amos.Rosmarin »

Hi,

What do you mean by changing the sql, I guess it's not just changing the value it's like doing for one steam row A=? and for another B>?
The only way doing so is to use user defined sql and replace the input parameter with a valid sql statment .
It's ugly but it will work. Don't use it for a lot of data - performance will be lousy.


HTH,
Amos
mleroux
Participant
Posts: 81
Joined: Wed Jul 14, 2004 3:18 am
Location: Johannesburg, South Africa
Contact:

Post by mleroux »

You can use a where field_name = ? clause in user-defined SQL the same way as DataStage does with a generated SQL query. Then, hook up a field to it via the GUI designer in your transformer.
Morney le Roux

There are only 10 kinds of people: Those who understand binary and those who don't.
bakul
Participant
Posts: 60
Joined: Wed Nov 10, 2004 2:12 am

Post by bakul »

I'll try to explain what I want to do.

I have to generate 2 types of queries based on an input parameter.
In one query , I need to select the rows with field 'STATUS' = 'A' .
In another query, I need to select the rows if the 'STATUS' is either 'A' or 'B' or 'C'.

The query to run depends on the input parameter. If the input is 'A', I use query 1 and if input is 'D' I use query 2. I need to do this in the same job.

I also need to count the number of records returned by such a lookup.

Is there any way I can accomplish this?


Thanks and Regards,
Bakul
crouse
Charter Member
Charter Member
Posts: 204
Joined: Sun Oct 05, 2003 12:59 pm
Contact:

Post by crouse »

If things are exactly as you state them, the first query is a subset of the second query.

Since the first select is a subset of the second, you could always use the second select. Filter the rows in the transformer stage with a constraint.

What/who needs to tell how many rows were returned? The answer determines how you should count the rows. Can you count the rows after the job runs, or do you need to do it inside the job?

-Craig
Craig Rouse
Griffin Resouces, Inc
www.griffinresources.com
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

You need 2 lookups. Have 2 outputs with constraints for each situation. Another way maybe using stage variables with if STATUS='A' set and second set of assignments if that is not true and the second situation 'STATUS' is either 'A' or 'B' or 'C' is true.
Mamu Kim
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

Consider an intermediate step where you move your lookup data into a hash file. Include your aggregation and a design that lets you use one lookup instead of two. First you dump in all the rows where the STATUS is equal to A with aggregation and a count field. Next you dump in where STATUS is A, B or C with aggregation. That way you run the aggregation function against the database against the entire recordset instead of running millions of individual aggregations through a lookup link.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Re: Dynamically generate where clause-Urgent

Post by ray.wurlod »

bakul wrote:I have a situation where I have to retrieve values for the same fields from a DB2 database every time but the where condition depends on the input data.
Is there any way to dynamically change the where clause in a DB2/UDB or ODBC stage used for lookup?

Thanks and regards,
Bakul
:roll:
You can use job parameters for any constant in the WHERE clause.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ailuro
Participant
Posts: 21
Joined: Wed Sep 10, 2003 11:09 pm
Location: GMT+8

Post by ailuro »

In fact you can pass where clause conditions as job parameters (including column names, operators and constants) e.g., STATUS = 'A', STATUS IN ('A', 'B', 'C').

Just define a job parameter, say CONDITION, and put #CONDITION# in your ODBC stage's Outputs > Selection > WHERE clause.
คาร์โล ตัน
bakul
Participant
Posts: 60
Joined: Wed Nov 10, 2004 2:12 am

Post by bakul »

Thanks all for the response! I have used job parameters and that seems to help!
Regards,
Bakul
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Another option to keep in mind... for the future. :wink:

You can dynamically generate your SQL statement and write it out to a flat file. Then, in your stage, set the Update Action to 'User Defined SQL File'. What you then put in the SQL area is the pathname of the file.

Not something I've used alot, but it has come in handy a time or two.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply