473,404 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Sort Results by Number of Hits

In MSSQL, is there a way to count the number of instances of a
substring within a string, so that I can sort by that?

For example:
table tst contains one column: tst_data

if tst_data = "the man with the plan"

I'd want a function that counts the occurances of "the"

count_substring(tst_data,'the') = 2

Basically, I'm making a search engine and I'd like to put the most
relavent hits at the top of the page.

Jul 23 '05 #1
2 1341
On 4 Feb 2005 11:46:46 -0800, se*********@gmail.com wrote:
In MSSQL, is there a way to count the number of instances of a
substring within a string, so that I can sort by that?


Hi seaofcrisis,

DECLARE @test varchar(100), @srch varchar(10)
SET @test = 'the man with the plan'
SET @srch = 'the'
SELECT (LEN(@test) - LEN(REPLACE(@test, @srch, ''))) / LEN(@srch)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: A Seel | last post by:
COUNTING NUMBER OF SELECTS MADE table mytable { id, data, hits }
8
by: san | last post by:
Hi, I wanted to know if this is possible and if so, how do I do it. Say, I have a query "SELECT * FROM Table WHERE Column="some_value". This executes on a very large data set and I would like...
1
by: Jack-of-all-traits | last post by:
This is a big problem and I really need help, no one seems to know how to solve this problem. I want to take the data from a record in a particular a field that contains the names of generic...
34
by: Mark Kamoski | last post by:
Hi-- Please help. I need a code sample for bubble sort. Thank you. --Mark
6
by: Tamir Khason | last post by:
Let's say I have Point and I want to sort it circle way (e.g. 2;2.4;1,8;2,8,5;4;8,2;7,1;4 The algo for this is: if ((p.X<p.X & p.Y<Avg(p).Y & p.Y<Avg(p).Y) | (p.X>p.X & p.Y>Avg(p).Y &...
3
by: Rick | last post by:
Hello, I ran Microsoft's free "Web Application Stress" tool to see how asp.net/c# performed against html. Are these results typical? Network: WAS ran on a server with a t3 Internet...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
40
by: RadiationX | last post by:
I have a problem that I really don't understand at all. In my previous post I could get started on my projects I just had a few problems with syntax errors. This problem is something that I don't...
5
by: mikevde | last post by:
Hi, Can anyone confirm whether it is possible to: a) use subqueries in mySQL b) use DISTINCT TOP in mySQL? I am trying to find a way to return the top 5 results in my table. For simplicity...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.