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 606871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:18:00+00:00 2026-05-13T17:18:00+00:00

I need implement simple search in small content table: id, name, description, content. Results

  • 0

I need implement simple search in small content table: id, name, description, content.
Results must be order by priorities

  1. name
  2. description
  3. content

it’s mean that if searched word was found in description field, it will be shown only after all rows that have dog in name field

What I did:

I tried create temp table with structure like table that I use but with another field priority. for each field, these I use for search, do insert select to temp table

Example:

  DECLARE @query NVARCHAR(255)


  CREATE TABLE #tbl_search
    (
      [id] INT NOT NULL ,
      [name] NVARCHAR(255) ,
      [description] NVARCHAR(MAX) ,
      [content] NVARCHAR(MAX) ,
      [priority] INT
    )    


    --searching in name field
  INSERT    INTO #tbl_search
            ( [ID] ,
              [name] ,
              [description] ,
              [content] ,
              [priority]

            )
            SELECT  [ID] ,
                    [name] ,
                    [description] ,
                    [content] ,
                    1
            FROM    [tbl_content]
            WHERE   name LIKE '%' + @query + '%'

    --searching in description field            
  INSERT    INTO #tbl_search
            ( [ID] ,
              [name] ,
              [description] ,
              [content] ,
              [priority]

            )
            SELECT  [ID] ,
                    [name] ,
                    [description] ,
                    [content] ,
                    2
            FROM    [tbl_content]
            WHERE   description LIKE '%' + @query + '%'
                    AND id NOT IN ( SELECT  id
                                    FROM    #tbl_search )
   --.....           

  SELECT    *
  FROM      #tbl_search
  ORDER BY  [priority]

  DROP TABLE #tbl_search
  • 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-13T17:18:00+00:00Added an answer on May 13, 2026 at 5:18 pm

    One way of doing it would be using the CASE keyword:

    SELECT name, description, content,
        priority = CASE
            WHEN name LIKE '%' + @query + '%' THEN 1
            WHEN desription LIKE '%' + @query + '%'  THEN 2
            WHEN content LIKE '%' + @query + '%'  THEN 3
        END CASE
    FROM tbl_content
    WHERE
        name LIKE '%' + @query + '%' OR
        desription LIKE '%' + @query + '%'  OR
        content LIKE '%' + @query + '%'
    ORDER BY priority ASC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 500k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer check the XmlRootAttribute class. May 16, 2026 at 2:05 pm
  • Editorial Team
    Editorial Team added an answer Add the @ sign before the start of your string… May 16, 2026 at 2:05 pm
  • Editorial Team
    Editorial Team added an answer The easiest way would be to loop through the DataTable… May 16, 2026 at 2:05 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm making a simple search form in rails. In my search view I have
I'm developing an ASP.NET app (c#) that need to authenticate users. To do that
A rather simple question really. I'm working on a project where I need to
I have a Service model with title:string description:string date:datetime. I would like to implement
I have some old C# plugin code that was implemented strictly with Reflection. In
I need to read a single file using multiple threads under Linux. There are
Classic scenario: Take user input, get a search-result and display it in pages to
Question Summary: Is there a better method than the one posted below to implement
I have an existing application (C#/Win forms). I need to add functionality to the
I have to implement the service provider of the OAuth protocol in a project

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.