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

  • Home
  • SEARCH
  • 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 639573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:51:28+00:00 2026-05-13T20:51:28+00:00

I have a table which contains my ads that can be searched in sql-server-2008.

  • 0

I have a table which contains my ads that can be searched in sql-server-2008. See the following piece of code. is_searchable in the ad_search table is basically the flag for whether this ad should be included in the search.

The three examples below produce unreasonable output in my mind:

In the first example 1000 records are returned. all with is_searchable set to 0. These rows are useless to me in this use case.

The second example shows the result of having a where clause filtering out is_searchable records that are not true. Because none were returned in the containstable in the from part of the query none were returned when the where clause was applied.

The third example only has the top_n_by_rank changed from 1000 to 4000.

So my question is how can I just get the TOP 1000 or n results with my “is_searchable =1” clause?

use live;

declare @search_text as varchar(2000) = '"*interlet*"'


--- TOP 1000 without clause (returns 1000 rows (all with is_searchable = 0)
select is_searchable, *
from CONTAINSTABLE (ad_search, searchText, @search_text, 1000) AS KEY_TBL
inner join ad_search (nolock) ON ad_search.ad_search_id = KEY_TBL.[KEY]
inner join ad_search_view_data on ad_search_view_data.ad_search_id = ad_search.ad_search_id


--- TOP 1000 with "where ad_search.is_searchable = 1" clause returns 0 rows
select is_searchable, *
from CONTAINSTABLE (ad_search, searchText, @search_text, 1000) AS KEY_TBL
inner join ad_search (nolock) ON ad_search.ad_search_id = KEY_TBL.[KEY]
inner join ad_search_view_data on ad_search_view_data.ad_search_id = ad_search.ad_search_id
where ad_search.is_searchable = 1

-- TOP 4000 
select is_searchable, *
from CONTAINSTABLE (ad_search, searchText, @search_text, 4000) AS KEY_TBL
inner join ad_search (nolock) ON ad_search.ad_search_id = KEY_TBL.[KEY]
inner join ad_search_view_data on ad_search_view_data.ad_search_id = ad_search.ad_search_id
where ad_search.is_searchable = 1 
  • 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-13T20:51:28+00:00Added an answer on May 13, 2026 at 8:51 pm

    Try this:

    DECLARE @N int
    SET @N=325
    
    SELECT TOP(@N)
        is_searchable, *
        from CONTAINSTABLE (ad_search, searchText, @search_text) AS KEY_TBL
        inner join ad_search (nolock) ON ad_search.ad_search_id = KEY_TBL.[KEY]
        inner join ad_search_view_data on ad_search_view_data.ad_search_id = ad_search.ad_search_id
        where ad_search.is_searchable = 1
        ORDER BY KEY_TBL.Rank DESC
    

    @N can be 1000 or whatever you want it to be

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a SQL server database, I have a table which contains a TEXT field
I have a table which contains my server status create table ServerStatus ( ServerId
I have a database structure that has a Person table which contains fields such
I have a database (NexusDB (supposedly SQL-92 compliant)) which contains and Item table, a
I have an Oracle table which contains event log messages for an application. We
I have a contacts table which contains fields such as postcode , first name
I'm currently dynamically building an asp:table which contains checkboxes these checkboxes have a CheckChanged
I have a table named categories, which contains ID(long), Name(varchar(50)), parentID(long), and shownByDefault(boolean) columns.
In a particular page i have a ascx control which contains a table. Now
I have a table which is full of arbitrarily formatted phone numbers, like this

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.