Replace logic is required

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sujathaeeshan
    New Member
    • Feb 2008
    • 22

    Replace logic is required

    Hello,

    The string column value looks like as below. Each value has a size of 15 withing a string

    '2.2020 30 4.0000'

    The column value should match with user input as below. The result should show equal when it is compared. Currently, it results not equal since it is a string comparision. The last digit '0' needs to be ignored for decimal values.

    '2.202 30 4.0'


    I need to handle the decimal values in such a way, if staring value with '.' and last digit is 0 then replace with space ''.
    so, it should look like

    '2 2 2 30 4 ' = '2 2 2 30 4 '
    When this string is compared, it results in EQUAL.


    I tried the below logic, which even replaces the interger value like 30 to 3 and 3000 to 3 and results in equal which is incorrect.
    RTRIM(REPLACE(R EPLACE(RT1.rate ,'''+@DOT+''',' ''+@SPACE+'''), '''+@ZERO+''', '''+@SPACE+''') ) = '''+REPLACE(REP LACE(@Rate,'.', ' '), '0', ' ')+''' '

    Ex:'2.2020 300 4.00' = '2.20200 30 4.0'

    After replace, string looks like
    Ex:'2 2 2 3 4 ' = '2 2 2 3 4 '

    It results as EQUAL which is incorrect. :( I need only decimal value to be replaced not integer.

    I am looking for a single string replace logic, any help would be greatly appreciated!!


    Thank you
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Why not convert it to int? The catch is, if your decimal portion is not 0, it might fail.

    Good Luck!!!


    ~~ CK

    Comment

    Working...