Replace problem on sqlserver

Asked

Viewed 133 times

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 bank, does not return to search.

I’m trying to use the Replace to take the formatting of the value of the bank to compare with the value coming from the page. this and 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

1 answer

1


At first it’s missing a ) at last replace, would be something like

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

The way it is there you end up repeating the digitable line, since you are concatenating the result of a replace with the result of gold replace (separated), applied in the same variable. Try using a replace inside the other.

For example:

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

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

  • Thanks for helping, more analyzing better what I posted, this giving replace in place, because the value of this field is being filled the page and the page has already been treated to accept only number, replace, I had to give the value that came from the bank, in case "TIT.Linhadigitavel", and I used the replace chained in the "TIT.Linhadigitavel". IF @charLinhaDigitavel IS NOT NULL BEGIN SET @SQL = @SQL + @CONDICAO + 'REPLACE(REPLACE(TIT.LinhaDigitavel,".","")," ","") LIKE ''%''+'+ '''' + @charLinhaDigitavel + '''' +'+''%'' ' SET @CONDICAO = ' AND ' END

  • I hope you helped solve your problem =)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.