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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:21:59+00:00 2026-05-29T08:21:59+00:00

I need to write a SQL Query for Advance search form shown as Image

  • 0

I need to write a SQL Query for Advance search form shown as Image below.

I wrote this partial sql query but i cant make it work correctly as it also get syntax error if user select second check-box and leaves the first check-box.

strSql = "SELECT ArticleID, ArticleTitle, ArticleDesc, ArticlePublishDate FROM art_Articles WHERE ";
strSql += "( ArticleVisible = 1 AND ArticleActive =1 AND LanguageID =" + LangID +" )";
strSql += " AND ";
strSql += " ( ";

if (cbArchiveTitle.Checked)
{ strSql += "  ArticleTitle LIKE N'%" + search + "%'  "; }
if (cbArchiveDesc.Checked)
{ strSql += " OR ArticleDesc LIKE N'%" + search + "%'  "; }
if (cbArchiveSummary.Checked)
{ strSql += " OR ArticleBodyDesc LIKE N'%" + search + "%'  "; }

strSql += ")";

Advanced Search Form
If i design my query something like this

 SELECT ArticleID, ArticleTitle, ArticleDesc, ArticlePublishDate FROM art_Articles WHERE 
 ( ArticleVisible = 1 AND ArticleActive =1 AND LanguageID =1 ) AND  
 (   ArticleTitle LIKE N'%Jobs%'   OR ArticleDesc LIKE N'%%'  ) 

And pass null value to fields which are not selected then i got all the row selected.

I would appreciate any help in designing this query to work for the form as show in the image

  • 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-29T08:22:00+00:00Added an answer on May 29, 2026 at 8:22 am

    You can add little trick to you code to resolve the issue with not selected first check box:

    strSql = "SELECT ArticleID, ArticleTitle, ArticleDesc, ArticlePublishDate FROM 
    
    art_Articles WHERE ";
    strSql += "( ArticleVisible = 1 AND ArticleActive =1 AND LanguageID =" + LangID +" )";
    strSql += " AND ";
    strSql += " ( 0 = 1 ";
    
    if (cbArchiveTitle.Checked)
    { strSql += " OR ArticleTitle LIKE N'%" + search + "%'  "; }
    if (cbArchiveDesc.Checked)
    { strSql += " OR ArticleDesc LIKE N'%" + search + "%'  "; }
    if (cbArchiveSummary.Checked)
    { strSql += " OR ArticleBodyDesc LIKE N'%" + search + "%'  "; }
    
    strSql += ")";
    

    But in general it’s not good approach to compose SQL statement in this way. You can consider to use either technologies like Linq or at least some query builder like SelectQueryBuilder

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

Sidebar

Related Questions

Im very new to SQL but need to write a query to do the
Ok this is driving me nuts, I need to write an SQL query that
I need to write a SQL-Server query but I don't know how to solve.
Need to write a SQL query to search special character in a column. Text
I need to write a SQL query which will get me those rows from
Since i'm a poor sql developer, i need support to write a sql query
I need to write some sql that will allow me to query all objects
I need to write a query on SQL server to get the list of
I need to write SQL Query to Retrive the Following Settings of SQL Logins
I need to write an SQL-Query for a csv-export. I have a table stores,

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.