Database: Sql Server
I have table column named page_text which contains following value
" I Love stackoverflow.com because i can post questions and get answers at any time. "
Using SQLQUERY i want to search the number of I
it has . So in this string it would should return 4.
I should be able to search anything.
Steps to solve: Add a column to your table and index it: ALTER TABLE tablename ADD COLUMN wordcount INT UNSIGNED NULL, ADD INDEX idxtablename_count (wordcount ASC); . Before doing your INSERT, count the number of words using your application.
SQL Server LEN() Function The LEN() function returns the length of a string. Note: Trailing spaces at the end of the string is not included when calculating the length. However, leading spaces at the start of the string is included when calculating the length.
LEN() Function in SQL Server LEN() function calculates the number of characters of an input string, excluding the trailing spaces. It is an expression that can be a constant, variable, or column of either character or binary data.
We can use LIKE Operator of SQL to search sub-string. The LIKE operator is used with the WHERE Clause to search a pattern in string of column. The LIKE operator is used in a conjunction with the two wildcards characters.
declare @search varchar(10) = 'I'
select len(replace(PageText, @search, @search + '#'))
- len(PageText) as Count from YourTable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With