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
bgs_vb
Premium Member
Posts: 79 Joined: Mon Jan 02, 2006 5:51 am
Post
by bgs_vb » Tue May 15, 2007 9:18 am
Hi,
can anybody tell me whether we can use if..then...else / CASE conditions in a stage variable..
thanks in advance.
bgs_vb
DSguru2B
Charter Member
Posts: 6854 Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX
Post
by DSguru2B » Tue May 15, 2007 9:20 am
If then else ----->Yes
Case ---- > No.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
bgs_vb
Premium Member
Posts: 79 Joined: Mon Jan 02, 2006 5:51 am
Post
by bgs_vb » Tue May 15, 2007 9:27 am
i have a case
source_fld should be compared for numeric or text
if numeric then < populate into target_fld _1> and < put 'n' to target_fld_txt>
otherwise <populate into target_fld_2> and <put 't' to target_fld_txt>
how do i solve it.
Thanks,
bgs_vb
DSguru2B
Charter Member
Posts: 6854 Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX
Post
by DSguru2B » Tue May 15, 2007 9:39 am
Use a simple if then else statement in stage variable to see if its numeric or not.
Use another if then else statement in the derivation to check on the value of stage variable and putting proper values for particular columns.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
us1aslam1us
Charter Member
Posts: 822 Joined: Sat Sep 17, 2005 5:25 pm
Location: USA
Post
by us1aslam1us » Tue May 15, 2007 9:43 am
How about just defining the Column derivations something like...
Code: Select all
target_fld _1 >> If num(in.col) then in.col else ''
target_fld _2 >> If num(in.col) then '' else in.col
target_fld _txt >> If num(in.col) then 'n' else 't'
I haven't failed, I've found 10,000 ways that don't work.
Thomas Alva Edison(1847-1931)
bgs_vb
Premium Member
Posts: 79 Joined: Mon Jan 02, 2006 5:51 am
Post
by bgs_vb » Tue May 15, 2007 9:45 am
i tried with Num(field) and stored it in stagevar
when i try to check like:
if (stagevar = 1) then
source_fld
else
'Txt'
end
it shows error
bgs_vb
chulett
Charter Member
Posts: 43085 Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO
Post
by chulett » Tue May 15, 2007 10:13 am
No 'end' required.
-craig
"You can never have too many knives" -- Logan Nine Fingers
bgs_vb
Premium Member
Posts: 79 Joined: Mon Jan 02, 2006 5:51 am
Post
by bgs_vb » Tue May 15, 2007 10:32 am
StageVariable Derivation - Num(DSLink4.Src)
Target Derivation - < If (StageVar = 1) Then DSLink4.Src > i am getting error here.
us1aslam1us
Charter Member
Posts: 822 Joined: Sat Sep 17, 2005 5:25 pm
Location: USA
Post
by us1aslam1us » Tue May 15, 2007 10:36 am
If condition then 'Result1' else 'Result2'. This is the syntax. What is the error message?
I haven't failed, I've found 10,000 ways that don't work.
Thomas Alva Edison(1847-1931)
chulett
Charter Member
Posts: 43085 Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO
Post
by chulett » Tue May 15, 2007 10:37 am
Do we have to guess what the error is? Where's your 'else'?
-craig
"You can never have too many knives" -- Logan Nine Fingers
bgs_vb
Premium Member
Posts: 79 Joined: Mon Jan 02, 2006 5:51 am
Post
by bgs_vb » Tue May 15, 2007 11:03 am
StageVariable Derivation - Num(DSLink4.Src)
Target Derivation - < If (StageVar = 1) Then DSLink4.Src Else 'T' End>
even if i put like this it shows 'General Syntax Error'
chulett
Charter Member
Posts: 43085 Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO
Post
by chulett » Tue May 15, 2007 11:20 am
As I said, there's no end required in a derivation if-then-else.
-craig
"You can never have too many knives" -- Logan Nine Fingers
bgs_vb
Premium Member
Posts: 79 Joined: Mon Jan 02, 2006 5:51 am
Post
by bgs_vb » Tue May 15, 2007 12:00 pm
Yes it works...
Thanks all...
ray.wurlod
Participant
Posts: 54607 Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:
Post
by ray.wurlod » Tue May 15, 2007 5:01 pm
Time to mark the thread as resolved, then?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.