Answered Derived Column Error

  • Monday, February 18, 2013 3:29 PM
     
     

    I have double pipes (||) in a CSV file, and I'd like to replace them with a single pipe (|) but I cannot do it.  Every-time I use the Derived column task to replace them it replaces the whole column with a single pipe. 

    REPLACE( «character_expression», «search_expression», «replace_expression» )

    Search expression is the Column name

    Character expression is the ||

    Replace expression is the |

    the output is:

    |

    |

    |

    |

    |

    |

    HELP!!!!!!!!!!!

All Replies

  • Monday, February 18, 2013 3:31 PM
     
     

    Also the end of some of the rows will end in a pipe, and I want it removed. tblwbhbwhw|, ==> tblwbhbwhw,

    How?????

  • Monday, February 18, 2013 3:47 PM
     
      Has Code

    Hello,

    The Syntax to Replace inside a derived transofrmation is

    REPLACE(COLNAME, "||", "|")

    The Column Name is the First Parameter followed by the String To Replace, and finally the replacement string. Hope this helps


    Regards, Dinesh



    • Edited by Dinesh Menon Monday, February 18, 2013 3:50 PM
    •  
  • Monday, February 18, 2013 3:52 PM
     
      Has Code

    Hi,

    As Dinesh has mentioned, use the REPLACE func as

    replace (col.name,"||","|")

    ie. replace 2 pipes with single. Please test and verify if this works.

    Thanks, hsbal

  • Monday, February 18, 2013 3:54 PM
     
     

    Thanks!

    Also if the column starts with | or ends with |  how do I remove it? A replace function with |, or ,| won't work.

    Examples:

    |NKRGL_RGL_ZZZ||NKRGL_NCM_ZZZ|
    |NKRGL_RGL_ZZZ||NKRGL_NCM_ZZZ|
    |GAEDU_SGA_ZZZ||GAEDU_GWN_ZZZ||GAEDU_DEK_ZZZ||GAEDU_FUL_ZZZ||GAEDU_CBB_ZZZ|

  • Monday, February 18, 2013 4:21 PM
     
     

    if the column within a CSV File starts with | or ends with |  how do I remove it?

    A replace function with |, or ,| won't work.

    Examples:

    |NKRGL_RGL_ZZZ||NKRGL_NCM_ZZZ|
    |NKRGL_RGL_ZZZ||NKRGL_NCM_ZZZ|
    |GAEDU_SGA_ZZZ||GAEDU_GWN_ZZZ||GAEDU_DEK_ZZZ||GAEDU_FUL_ZZZ||GAEDU_CBB_ZZZ|

    • Merged by David DyeModerator Monday, February 18, 2013 4:48 PM referenced post ID already requests assistance for this topic
    •  
  • Monday, February 18, 2013 4:22 PM
     
     Answered

    Hi, on the first column you can check the 1st character... 

    (Substring(colname,1,1)=="|")?substring(colname,2,len(colname)-1):colname

    And on the last column you can check the last character...

    (Substring(colname,len(colname),1)=="|")?substring(colname,1,len(colname)-1):colname


    ... and strip off should it equal a pipe symnbol...
  • Monday, February 18, 2013 4:28 PM
     
     

    Add another Dervied Column after the original one to Replace (ColName, "|","") That will help

    See image below.


    Regards, Dinesh


    How would you get rid of leading and ending pipes(|)?
  • Monday, February 18, 2013 4:30 PM
     
     Proposed Has Code

    Sorry about the earlier answer.

    All you need is to include the Derived Transformation with the following code

    Trim(Replace(ColName,"|",""))
    This will replace the pipleines throughout your string. you do not need to do the replace twice. It does not matter if the pipeline is at the beginning or end the Replcae will search your colum and replace all | with an empty space.


    Regards, Dinesh


  • Monday, February 18, 2013 4:35 PM
     
     

    Hi, on the first column you can check the 1st character... 

    (Substring(colname,1,1)=="|")?substring(colname,2,len(colname)-1):colname

    And on the last column you can check the last character...

    (Substring(colname,len(colname),1)=="|")?substring(colname,1,len(colname)-1):colname


    ... and strip off should it equal a pipe symnbol...

    Good job!!

    The leading | disappeared but the ending | is till there!

    Thanks anyway.

  • Monday, February 18, 2013 4:41 PM
     
      Has Code
  • Monday, February 18, 2013 4:43 PM
     
     

    Hi, on the first column you can check the 1st character... 

    (Substring(colname,1,1)=="|")?substring(colname,2,len(colname)-1):colname

    And on the last column you can check the last character...

    (Substring(colname,len(colname),1)=="|")?substring(colname,1,len(colname)-1):colname


    ... and strip off should it equal a pipe symnbol...

    Does this allow for a reverse function to remove it that way?
  • Monday, February 18, 2013 4:45 PM
     
     
    Yep Dinesh... good one.