Count String In SQL Server

T-SQL is the language for find data in database. It can insert, search, update and delete all data. We also can join table or find complexly data(data in other table). we also use T-SQL to make application or function to run in database. Today I want to know some knowledge about count string in SQL Server.

Ex: We have string as below

@str='9-9-99-99-999'

We want to count symbol (-) in this string
Please write this statement:

Declare @countStr varchar(100)
Set @countStr=Len(Replace(@str,'9',''))
Print @countStr

It will show result =4

I will have other tips about SQL Server to share. If you have any problem please comment. I will try to help and find the solution for you.

No comments:

Post a Comment