location of '-' in the comments Please Define Or Explain It To me

  • 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[/url]

  • 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

    How to post a question to get the most help http://www.sqlservercentral.com/articles/Best+Practices/61537

  • 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