Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

location of '-' in the comments Please Define Or Explain It To me Expand / Collapse
Author
Message
Posted Thursday, July 17, 2014 3:36 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, July 17, 2014 3:32 AM
Points: 1, Visits: 0
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!

_________________________
Hair Transplant India


Post #1593449
Posted Thursday, July 17, 2014 3:39 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 3:12 PM
Points: 1,020, Visits: 3,251
You can use PATINDEX or CHARINDEX to do that.


On two occasions I have been asked, "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" ... I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
—Charles Babbage, Passages from the Life of a Philosopher
Post #1593451
Posted Thursday, July 17, 2014 3:48 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 1:42 PM
Points: 1,990, Visits: 5,183
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
Post #1593457
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse