Page 1 of 1

Remove Zero Rows from a String COlumn

Posted: Fri Dec 16, 2011 10:43 pm
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....

Posted: Fri Dec 16, 2011 11:48 pm
by pandeesh
try this:

Code: Select all

if trim(input)='0' then SPACE(1) else input

Posted: Fri Dec 16, 2011 11:53 pm
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

Posted: Fri Dec 16, 2011 11:54 pm
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

Posted: Sat Dec 17, 2011 1:15 am
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'

Posted: Sat Dec 17, 2011 8:28 am
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.

Posted: Sat Dec 17, 2011 8:48 am
by pandeesh
Awesome Craig! :)