Replace problem in sqlserver

0

I have a field in the page that receives only number, but when I compare in the function this value of the page with what is in the database, it does not return to search.

I'm trying to use Replace to strip the formatting of the bank's value to compare with the value coming from the page. this is the code I'm using

IF @charLinhaDigitavel IS NOT NULL   
            BEGIN                              
                SET @SQL = @SQL + @CONDICAO + 'TIT.LinhaDigitavel LIKE ''%''+'+ '''' +replace( @charLinhaDigitavel,''.'',''''),replace( @charLinhaDigitavel,'' '','''' + '''' +'+''%'' '
                SET @CONDICAO = ' AND '   
            END
    
asked by anonymous 21.08.2015 / 21:07

1 answer

1

At first it is missing a ) in the last replace , it would be something like

replace( @charLinhaDigitavel,'' '','''') + '''' +'+''%'' '

As you are there, you end up repeating the digitable line, since you are concatenating the result of a replace with the% gold result% (separated), applied to the same variable. Try to use replace inside the other.

For example:

replace(replace(@charLinhaDigitavel,'' '','''' + ''''),''.'','''')

This way you will always apply to get the result of replace more "internal" and apply replace more "external".

    
21.08.2015 / 21:29