July 17, 2014 at 3:36 am
Can anybody please help me on how to define the location of '-' in the comments?
For example, I have a comment like 'Work (210) 401-6838 for debtor(1) 'Guzman, Tarrasa' status changed from Good to Bad'.
I want to know which SQL function to use to locate the '-' inside the phone number. Here, it is 14th character in the comment. Then I can use the SUBSTRING ( expression ,start , length ) to take phone number out as 2104016838 format.
Thanks a lot!
_________________________
July 17, 2014 at 3:39 am
You can use PATINDEX or CHARINDEX to do that.
How to post a question to get the most help http://www.sqlservercentral.com/articles/Best+Practices/61537
July 17, 2014 at 3:48 am
Quick suggestion
😎
DECLARE @COMMENT NVARCHAR(200) = N'Work (210) 401-6838 for debtor(1) ''Guzman, Tarrasa'' status changed from Good to Bad';
SELECT REPLACE(@COMMENT,N'-',N'') AS CLEAN_COMMENT
Result
CLEAN_COMMENT
-----------------------------------------------------------------------------------
Work (210) 4016838 for debtor(1) 'Guzman, Tarrasa' status changed from Good to Bad
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply