Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 583315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:46:46+00:00 2026-05-13T14:46:46+00:00

I have an asp.net web page with a simple search text box that returns

  • 0

I have an asp.net web page with a simple search text box that returns matching rows from a MSSQL 2005 database. It is currently using a LIKE statement to bring back matches, but forces the user to to type an exact phrase. Users want a more Google search type experience and so I have decided to set up and index the needed tables with FTS.

I would like the users search word or words to be used in a CONTAINS search with NEAR separating each word they type into the text box. I’m a new developer and do not know how to do this, or if there is already a built in function to cover this.

So for example, if a user types “Sawyer Tom” into the search box the query should function like this:

SELECT BookID, BookTitle
FROM tblBooks
WHERE CONTAINS(BookTitle, ‘Sawyer NEAR Tom’)

And return:

12032 The Adventures of Tom Sawyer

Currently using the like statement I have now the user search would find no matches.

If the user types simply Sawyer the query should function simply like this:

SELECT BookID, BookTitle
FROM tblBooks
WHERE CONTAINS(BookTitle, ‘Sawyer’)

Returning:

12032 The Adventures of Tom Sawyer
72192 Roy Crane’s Buz Sawyer: The War in the Pacific (Vol. 1)

My current code just plugs in the search string into the query like this:

SELECT BookID, BookTitle
FROM tblBooks
WHERE CONTAINS(BookTitle, @Search)

Which obviously doesn’t work. How can I separate each word automatically with NEAR?

Thanks so much in advance for any help you can provide!

-David

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:46:46+00:00Added an answer on May 13, 2026 at 2:46 pm

    First, you would need to split your input @Search variable into words.

    Here’s a blog post with a UDF that will accomplish that:

    T-SQL to Split a varchar into Words

    Next, you would look through each word returned, and concatenate each word with a NEAR query.

    Something like this:

    declare @words as TABLE(wordNum int identity primary key, word nvarchar(max))
    
    insert into @words select [value] from  dbo.SplitWords('my dog has fleas')
    
    declare @wordCount int
    select @wordCount = COUNT(*) from @words
    
    declare @searchString nvarchar(max)
    set @searchString = ''
    
    declare @thisWord nvarchar(max)
    set @thisWord = ''
    
    declare @i int
    set @i = 1
    WHILE @i <= @wordCount
    BEGIN
        select @thisWord = word from @words where wordNum = @i
        if @i = @wordCount
            select @searchString = @searchString + @thisWord
        else
            select @searchString = @searchString + @thisWord + ' NEAR '
        SET @i = @i + 1
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple asp.net web page that contain a table with about 5
I have a ASP.NET web page that contains many textboxes. Each textbox has a
I have to do a asp.net web page that when load will say something
I have a simple ASP.NET web form on a page, which is contained in
I have an ASP.NET web page(Not MVC ) (HomePage.aspx) and another page (PRiceList.aspx).I have
I have an ASP.Net web page, which uses a Master Page template. The page
I have an asp.net web page (C# 2008) where the user would enter an
On an ASP.NET web page I have an EntityDataSource: <asp:EntityDataSource ID=EntityDataSourceOrders runat=server ConnectionString=name=EntitiesContext DefaultContainerName=EntitiesContext
I have a gridview in asp.net web page. The datasource comes sql server table.
I have a DropDownList in my asp.net web page. The RequiredFieldValidator is not working.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.