Nulls in dates, Rnd function problems

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
gateleys
Premium Member
Premium Member
Posts: 992
Joined: Mon Aug 08, 2005 5:08 pm
Location: USA

Nulls in dates, Rnd function problems

Post by gateleys »

I have a stage variable sv_weeks which performs a DateDifference. I had to check NULL condition for fire_date, if it is NULL set to 27, else set it to difference between the 2 dates of type Timestamp (23,3).

Code: Select all

sv_weeks = If fromX.fire_date = char(128) then 27 else DateYearFirstDiff(fromX.fire_date, fromX.hire_date)/7
Now, emp_duration (integer 3) =

Code: Select all

if sv_weeks < 27 then weeks else 0
Problems:
1. The transformer is followed by an AGG (where derivation is Last(emp_duration) and type interger 3)...which when run warns -
myJob..AggSal: At row 4429, link "outTrans1", while processing column "outAgg1.emp_duration"
Value treated as NULL
Attempt to convert String value "" to Long type unsuccessful

2. If I use the Rnd function in the DateYearDifference function to round to the next week, then sv_weeks (which are NULL) are evaluated to being > 27 and temp_duratoin takes the else path. But I want it to be set to 27 if it is Null.

Please tell me where I have gone wrong.
ketfos
Participant
Posts: 562
Joined: Mon May 03, 2004 8:58 pm
Location: san francisco
Contact:

Post by ketfos »

Hi,
You are trying to calculate the diff between to date fields.
fromX.fire_date, fromX.hire_date)/7

Both teh fields are same.

Ketfos
gateleys
Premium Member
Premium Member
Posts: 992
Joined: Mon Aug 08, 2005 5:08 pm
Location: USA

Post by gateleys »

ketfos wrote:Hi,
You are trying to calculate the diff between to date fields.
fromX.fire_date, fromX.hire_date)/7

Both teh fields are same.

Ketfos
If only you would "see" properly..they are 2 different dates- hire and fire.
May be you had an illusion.
ketfos
Participant
Posts: 562
Joined: Mon May 03, 2004 8:58 pm
Location: san francisco
Contact:

Post by ketfos »

Hi,
I am sorry. I was just trying to help you.

Thanks so much for a nice response.

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

Post by ray.wurlod »

Prefer IsNull() to "= Char(128)". It is more efficient and more reliable.

The Rnd() function generates a random number. You need the Fix() or Oconv() function to do rounding.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
gateleys
Premium Member
Premium Member
Posts: 992
Joined: Mon Aug 08, 2005 5:08 pm
Location: USA

Post by gateleys »

ray.wurlod wrote:Prefer IsNull() to "= Char(128)". It is more efficient and more reliable.

The Rnd() function generates a random number. You need the Fix() or Oconv() function to do rounding.
Hi Ray, I tried Fix() to round the number as below, but it still doesn't round it. Below is the code which takes in 2 dates and computes number of weeks between them. If number is 2.1 or 2.9, it should still return 3.

Code: Select all

Fix((DateYearFirstDiff(TheLink.date2, TheLink.date1))/7)
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Curious if you read the online help for the Fix function? With no options it rounds to a default precision of four - and you want zero.

Plus, what you want is not strictly 'rounding' as rounding would take 2.9 up to 3 but would also take 2.1 down to 2. You need to play the old game of adding .5 to the computed value before rounding to get the results you desire.

I've never had the pleasure of fix'ing anything before but I'd try:

Code: Select all

Fix((DateYearFirstDiff(TheLink.date2,TheLink.date1)/7)+.5,0)
and see if that works. Of course it is late and I have yet to go home, so no guarantees. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Fix(number, precision, mode)

Mode rounds excess digits if 0, truncates if non-zero.

All this and more is in the DataStage BASIC manual.
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 »

Mode rounds excess digits if 0 or not specified, truncates if non-zero.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Good catch. Of course I know that the function says, internally, "if not specified use 0", but not everyone else does.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply