Remove Zero Rows from a String COlumn

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
Magesh_bala
Participant
Posts: 86
Joined: Mon Nov 27, 2006 3:42 am
Location: Wilmington

Remove Zero Rows from a String COlumn

Post by Magesh_bala »

Hi All,

I have a scenario where I need to replaces all the rows with Zero into Single space...

Invalid Rows

Eg:
0
00
000
0000

The column is defined as Varchar(20) so it can have any combination of Zero values starting from 1 to 20 zeros

I need to remove all the rows where it has Zero's as defined above. It can be of any combination.
Your help will be really appreciated.

Valid Rows
-------------
1010
0001
1000

I dont want to make any changes to the valid Rows....
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

try this:

Code: Select all

if trim(input)='0' then SPACE(1) else input
pandeeswaran
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

i have misunderstood the requirement

Have a stage variable

Code: Select all

if AsInteger(input)+0=0 then 1 else 0
I believe even AsInteger() also not required.

In the transformer set the constraint as StageVar=0

so that non zero strings will be passed
pandeeswaran
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

If you need to retain the zero strings with a space then,

Code: Select all

if AsInteger(Input)+0=0 then SPACE(1) else input
pandeeswaran
zulfi123786
Premium Member
Premium Member
Posts: 730
Joined: Tue Nov 04, 2008 10:14 am
Location: Bangalore

Post by zulfi123786 »

As the colum is defined to be varchar its always a good practise to check before type conversion using IsValid() so the above posted code with slight modification would look like

Code: Select all

If Not(Isvalid(int32,input)) then SetNull() Else If AsInteger(input)=0 then ' ' Else input
in the above code there are two assumptions:
1. if its not a valid integer then Null has to be populated
2. the input column is of the sql type 'integer'
- Zulfi
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

There's no conversion of any kind here, they just need a simple check for all zeroes so those rows can be filtered out. Stage variable svIsValid:

Code: Select all

Convert('123456789','',YourField) <> YourField
Use svIsValid as your constraint.
-craig

"You can never have too many knives" -- Logan Nine Fingers
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

Awesome Craig! :)
pandeeswaran
Post Reply