SQL- count character in a string
There was requirement from my customer to count the special character available in particular field in the table and generate the report to show if this character is repeating more than 3 times in the field.
I did not find any inbuilt function in SQL server and here is the solution I have provided.
String - "45ghf-8293-89kj-kfji"
SQL, we have function to retrieve the total length of the string using LEN function. if we are able to reduce the special character from the string and subtract this length with the actual length we will be getting the number of occurrence.
SELECT '45ghf-8293-89kj-kfji',LEN('45ghf-8293-89kj-kfji'),LEN(REPLACE('45ghf-8293-89kj-kfji','-','')), LEN('45ghf-8293-89kj-kfji')- LEN(REPLACE('45ghf-8293-89kj-kfji','-',''))
I did not find any inbuilt function in SQL server and here is the solution I have provided.
String - "45ghf-8293-89kj-kfji"
SQL, we have function to retrieve the total length of the string using LEN function. if we are able to reduce the special character from the string and subtract this length with the actual length we will be getting the number of occurrence.
SELECT '45ghf-8293-89kj-kfji',LEN('45ghf-8293-89kj-kfji'),LEN(REPLACE('45ghf-8293-89kj-kfji','-','')), LEN('45ghf-8293-89kj-kfji')- LEN(REPLACE('45ghf-8293-89kj-kfji','-',''))
Thanks Siva
ReplyDeleteReally nice post.Thanks for sharing.
ReplyDeletepersonalrekrutierung
I like this post .Thanks for sharing.
ReplyDeleteInternet Marketing Dienstleistungen in Deutschland
Thanks for sharing this.
ReplyDeletePost graduation education in germany
really good
ReplyDeletejobbörse südwestfalen
Excellent information with unique content and it is very useful to know about the information based on blogs.
ReplyDeleteErp In Chennai
Great Article Artificial Intelligence Projects
ReplyDeleteProject Center in Chennai
JavaScript Training in Chennai
JavaScript Training in Chennai