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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:51:03+00:00 2026-05-17T17:51:03+00:00

Im currently making a very simple WebApp on a Website using ASP.NET Framework using

  • 0

Im currently making a very simple WebApp on a Website using ASP.NET Framework using C# in Visual Studio 2010.

The website will connect to my SQL EXPRESS server running on my laptop (Its all locally based)

I have a table defined as below

CREATE TABLE Users(
 userName varchar(50),
 email varchar(50),
 firstName varchar(50),
 lastName varchar(50),
 gender varchar(50),
 birthday date,
 age int,
 location varchar(50),
 gname varchar(50)
 PRIMARY KEY (userName, email))
GO

Now, I have a page on my website called Users. NOTE: gname means Group Name (ie, users join an interest group.)

Here I have a form that looks something like this:

UserName:
Gender:
Age:
GroupName:
Location:

Now, this would mean I have 5 different fields, and hence, I would have to write 25 SQL statements for each different case. Which I find pretty naive.

I tried Googling around for Dynamic SQL Statements, which do not seem to be addressing my problem here (or at least I don’t understand how they address my problem).

Can anyone point me in the right direction to learn how to implement SQL statements thats smart enough to generate queries based on which field has been given input by the user?

Apologise to anyone who might think I have not done my research to something that might seem rather simple.

-Ali

  • 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-17T17:51:04+00:00Added an answer on May 17, 2026 at 5:51 pm

    Consider a combination of @GôTô’s code and the below SQL

    select * 
    from Users u
    where   (@username is null or Username like '%'+ @username + '%')
        AND (@Gender is null or Gender = @gender)
        AND (@age is null or Age = @age)
        AND (@gname is null or gname = @gname)
        AND (@location is null or location = @location)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently in the process of making a new ASP.net MVC website, and
I'm making a winform in C# using Visual Studio 2008. Currently, I have a
I have a question about tables in MySQL. I'm currently making a website where
Is there a way to aid gmail in making threads? We are currently using
Currently we have a hybrid ASP/PHP setup connecting to a SQL Server 2005 database.
I was wondering if there was a way to execute very simple tasks on
I'm currently having difficulty finding a way of making my loops work. I have
I'm making a small language that is very similar to hlsl but supports only
At my current job I've been working on making web apps with Java, Tapestry,
Currently, I don't really have a good method of debugging JavaScript in Internet Explorer and

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.