Wrox Programmer Forums Replace logic is required
 |
 SQL Server 2005 General discussion of SQL Server *2005* version only.
 Welcome to the p2p.wrox.com Forums. You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com

May 10th, 2012, 01:20 AM
 suji Authorized User Join Date: Feb 2008 Posts: 16 Thanks: 0 Thanked 0 Times in 0 Posts
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(REPLACE(RT1.rate,'''+@DOT+''','''+@S PACE+'''), '''+@ZERO+''', '''+@SPACE+''')) = '''+REPLACE(REPLACE(@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

 Similar Threads Thread Thread Starter Forum Replies Last Post How can I acheive this logic? OnDistantShores XSLT 3 February 26th, 2010 04:16 AM help to solve the logic pradeepn XSLT 4 May 22nd, 2007 06:07 AM And/Or Logic??? ninel SQL Server 2000 2 February 9th, 2007 11:33 AM Tricky logic (for me) cedwards Dreamweaver (all versions) 5 April 5th, 2006 04:47 PM Mixing Data access logic and business logic polrtex BOOK: Professional Jakarta Struts 0 December 15th, 2003 07:19 PM