Thursday, March 22, 2012

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???http://www.dbforums.com/t648578.html

select len(YourCol)-len(replace(YourCol,'1',''))

No comments:

Post a Comment