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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:03:09+00:00 2026-06-02T19:03:09+00:00

I am building a system where the user can search users in a forum

  • 0

I am building a system where the user can search users in a forum by gender, age language, users interest.

I have got this stored procedure:

ALTER PROCEDURE dbo.FindFriends
    (
    @language int,
    @country nvarchar(50),
    @sex int,
    @ageFrom int,
    @ageTo int,
    @category nvarchar(50)
    )
AS
    SELECT u.*, cat.*
    FROM  [User] AS u
    INNER JOIN categories AS cat ON u.user_id=cat.user_id 
    WHERE (age_presenentation BETWEEN @ageFrom AND @ageTo) AND lingo=@language AND sex=@sex AND cat.category_name=@category

This statement is what I want. But sometimes, the user may not enter some of the fields. For example, the user might search users by category alone.. This will result in no users appearing, since I am using “And” operator. Is there a way to combine the logic, so that if any of the sql variables (e.g. @category, @angeTo) are given as empty, the statement will not include them?

  • 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-06-02T19:03:12+00:00Added an answer on June 2, 2026 at 7:03 pm

    I have run into this many times.

    Try:

    WHERE (age_presenentation BETWEEN @ageFrom AND @ageTo)
    AND ((@language IS NULL) OR (lingo=@language))
    AND ((@sex IS NULL) OR (sex=@sex))
    AND ((@category IS NULL) OR (cat.category_name=@category))
    
    You can apply the same logic to the @ageFrom as well:
    ((@ageFrom IS NULL) OR (age_presenentation BETWEEN @ageFrom AND @ageTo))
    

    But that may be too many records.

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

Sidebar

Related Questions

In the system I am building user CAN NOT register them selves. The users
I'm building a part of a system where the user can define views from
I am building an online hotel booking system.... Using php and mysql.... Users can
I am building a system in which the user can build thre own navigation
i'm building a system where users can earn XP-s. Those points are used in
so let's say i'm building this contact management system. There is a USER table
I am currently building a dynamic url tab system that user can say what
I'm building a rating system where a user can rate something from 1-5 stars.
I'm building a system, where user can upload a file as data (not for
I am building a system where some users have access to certain pieces of

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.