can we use if..then...else conditions in a stage variable

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
bgs_vb
Premium Member
Premium Member
Posts: 79
Joined: Mon Jan 02, 2006 5:51 am

can we use if..then...else conditions in a stage variable

Post by bgs_vb »

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
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

If then else ----->Yes
Case ---- > No.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
bgs_vb
Premium Member
Premium Member
Posts: 79
Joined: Mon Jan 02, 2006 5:51 am

Post by bgs_vb »

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
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

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
Charter Member
Posts: 822
Joined: Sat Sep 17, 2005 5:25 pm
Location: USA

Post by us1aslam1us »

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
Premium Member
Posts: 79
Joined: Mon Jan 02, 2006 5:51 am

Post by bgs_vb »

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
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

No 'end' required.
-craig

"You can never have too many knives" -- Logan Nine Fingers
bgs_vb
Premium Member
Premium Member
Posts: 79
Joined: Mon Jan 02, 2006 5:51 am

Post by bgs_vb »

StageVariable Derivation - Num(DSLink4.Src)

Target Derivation - < If (StageVar = 1) Then DSLink4.Src > i am getting error here.
us1aslam1us
Charter Member
Charter Member
Posts: 822
Joined: Sat Sep 17, 2005 5:25 pm
Location: USA

Post by us1aslam1us »

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
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

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
Premium Member
Posts: 79
Joined: Mon Jan 02, 2006 5:51 am

Post by bgs_vb »

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
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

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
Premium Member
Posts: 79
Joined: Mon Jan 02, 2006 5:51 am

Post by bgs_vb »

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 »

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.
Post Reply