Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2003
    Location
    Penang, Malaysia
    Posts
    212

    Question Unanswered: Count "SPECIFIC" characters in a string

    How do I count the number of specific characters in a string ?

    Example:

    declare @var as varchar(50)
    set @var="1abc1efg1"


    If I wanted to count the "1"...I'll get "3" for answer.
    This could maybe done by using a while loop, but is there any T-SQL command for this?????
    Patrick Chua
    LBMS ( Learn By My Self) NPQ ( No paper Qualification )

  2. #2
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    [sniped]
    http://www.dbforums.com/t648578.html
    [/sniped]

    select len(YourCol)-len(replace(YourCol,'1',''))
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •