concatenation of four column into a single column

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
Sandeepch19
Participant
Posts: 36
Joined: Fri May 21, 2010 12:40 am
Location: Bangalore

concatenation of four column into a single column

Post by Sandeepch19 »

I have four input column, a,b,c and d where in the output column is E
i am doing the concatenation of a:b:c:d to give the output E. But my problem is even if any of the four input column is null the E column should concatenate other three fields and give the output . It should not be null. Only case where it can be null is when all the four fields are null. I have solution for this that is using stage variables. Please let me know if you have any other solutions to this.
Sandeep Chandrashekar
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Wrap each field in a NullToEmpty() call during the concatenation, no intermediate stage variables required..
-craig

"You can never have too many knives" -- Logan Nine Fingers
Sandeepch19
Participant
Posts: 36
Joined: Fri May 21, 2010 12:40 am
Location: Bangalore

Post by Sandeepch19 »

thank you,
But nulltoempty() is not working in 7.5 . stage variable is the only option?
Sandeep Chandrashekar
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Define 'not working'. It is a perfectly valid function in the 7.x version of the product, one that I made extensive use of back in the day, doing exactly the kind of things you've asked about here.
-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 »

You want to allow for null output, so you will need an If..Then..Else to cover the possibility that all source columns are null.

Code: Select all

If IsNull(InLink.colA) And IsNull(InLink.colB) And IsNull(InLink.colC) And IsNull(InLink.colD) Then @NULL Else NullToEmpty(InLink.colA) : NullToEmpty(InLink.colB) : NullToEmpty(InLink.colC) : NullToEmpty(InLink.colD)
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 »

... unless you want the result to be an empty string in that case. If so, stick with just the "else" portion. :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 »

Sandeepch19 wrote:Only case where it can be null is when all the four fields are null.
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 »

Of course, just offering an alternative. Perhaps an EmptyToNull() wrapper around the whole thing? :wink:
-craig

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