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 an ASP.NET web page that displays a variety of fields that need
I have an asp.net web page with a ton of code that is handled
I have an asp.net web page written in C#. Using some javascript I popup
I have an ASP.NET web page with a Login control on it. When I
I have a asp.net web page with place holder control and Menu control when
I have an asp.net update web app. Users go the the page, hit the
I'm writing a web page in ASP.NET. I have some JavaScript code, and I
In ASP.net 2.0, the PreviousPage property of a web page does not have a
Background I have a page on my ASP.NET MVC web app for users to
I have a script that appends some rows to a table. One of the

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.