Home Forums Programming General define the location of '-' in the comments RE: define the location of '-' in the comments

  • yi.wang 12733 (8/16/2013)


    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!

    yi

    CHARINDEX will get you the location of a character.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/