Use of selfmade routine

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
jzijl
Participant
Posts: 23
Joined: Thu Jul 20, 2006 6:09 am

Use of selfmade routine

Post by jzijl »

Hello,

I made a routine to determine end of month (YYYY-MM-DD) based on year and month in DataStage (typed Transform Function). Therefore I can use this function in the Transformer to drop rows. This works.

Actually I wanted to use this function in the WHERE-clause of my SQL statement as this looks more efficient to me, less rows to upload. This leads to the mesage: Function unknown. Probably because this is not a SQL-function.

Can someone help me to inform me how I can build routines to use in the SQL WHERE- clause when retrieving data via ODBC-stage from a MS SQL Server and via the DB2-stage?

Thanks in advance.

Jan
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Welcome aboard. If your database supports creating functions, that's where you need to do it. DS Functions are only good inside DS. When DS issues the SQL to the souce/target database the SQL is in the hands of the database, any use of functions in the SQL must be valid within the database itself.

If your date is a fixed value, consider deriving it first and passing it in as a job parameter. Then, your SQL can make use of a job parameter, which is resolved at the time the SQL is sent to the database.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You can do it in SQL with SQL functions, not with DataStage functions as Ken indicated. One way is to determine whether the difference between the date and the first of the subsequent month is 1. If that is true, then your date is the last day of its month. Different databases use different date manipulations, but most - if not all - can achieve this result.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

ray.wurlod wrote:You can do it in SQL with SQL functions, not with DataStage functions as Ken indicated.
You slight me sir :lol: I said no such thing. Please re-read my post.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Let me change the punctuation to indicate what I meant. 8)

You can do it in SQL with SQL functions, not with DataStage functions, as Ken indicated.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Thanks, that simple comma changes the tone.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Eats, Shoots and Leaves. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Usually MSQL and any other database have quite similar syntax for case statments. You can do that in you SQL as well.

The error you posted seems to be that either you are not allowed to use the functions or your SQL is no right.
First test your SQL in the enterprise manager of MSSQL or the DB2connect for DB2.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

chulett wrote:Eats, Shoots and Leaves. :wink:
The parody (Eats, Shites and Leaves) is funnier.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Can you say 'Shites' here? Hmm... guess so. I'll have to check it out.
-craig

"You can never have too many knives" -- Logan Nine Fingers
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

Best 3 word answers ever. "Take. Adapt. Shine." pretty good too. :wink:
Mamu Kim
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

chulett wrote:Can you say 'Shites' here? Hmm... guess so. I'll have to check it out.
Then you might like the "strict standards" enforced at the The Manly Daily ( newspaper in Sydney, Australia), which reported last week that Senator Bill Heffernan had rejected certain allegations as "b--lshit".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
jzijl
Participant
Posts: 23
Joined: Thu Jul 20, 2006 6:09 am

Post by jzijl »

I understood that it can be solved by making your own User Defined Functions in MSS.
Using a job paramater is unfortunately not possible as I have only the year and month and have to determine the end of month.

Thanks all.

Jan
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Should still be possible.
Get the date of the first of next month from the three components:
Year = (If Month = 12 Then Year + 1 Else Year)
Month = (If Month = 12 Then 1 Else Month + 1)
Day = 1
Build these into a date, and use a DateDiff function to calculate the date of the day prior.
(I'm not fully au fait with SQL Server's SQL syntax, but that would be the algorithm. You may need CASE statements in an inner query to generate equivalents to the If tests given.)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

If doing this is SQL scares you then you can do it in DataStage, build a parameter file and then call the job by passing the parameters to it, via the parameter file.
You can also build the date inside a job and within that job itself, in the transformer, call the second job that takes in the date parameter and selects the required rows. Look into the UtilityRunJob() routine.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Post Reply