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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:04:47+00:00 2026-05-12T15:04:47+00:00

I am working on a web project where I have to retrieve (let’s say)

  • 0

I am working on a web project where I have to retrieve (let’s say) employee records. In some cases I have to retrieve a single record by providing an EmployeeID. In other cases, I have to retrieve multiple employee records by providing a SectorID. This logic could be expanded to cover additional scenarios: get all employee records, get employee records by qualification, etc.

Is it good practice to use one single stored procedure that accepts a variable number of parameters to handle different scenarios (using default values when the parameter is not provided). Ex:

CREATE PROCEDURE [dbo].[GetEmployeeRecords]
(
    @employeeID int = -1,
    @sectorID int = -1
)

AS

BEGIN

    SELECT  EmployeeID,
            EmployeeFirstName,
            EmployeeLastName,
            s.SectorName

    FROM dbo.Employees e

    INNER JOIN Sectors s ON e.SectorID = s.SectorID

    WHERE (e.EmployeeID = @EmployeeID OR @EmployeeID = -1)

    AND (e.SectorID = @SectorID OR @SectorID = -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-12T15:04:48+00:00Added an answer on May 12, 2026 at 3:04 pm

    here is a very comprehensive article on this topic:

    Dynamic Search Conditions in T-SQL by Erland Sommarskog

    it covers all the issues and methods of trying to write queries with multiple optional search conditions

    here is the table of contents:

       Introduction
          The Case Study: Searching Orders
          The Northgale Database
       Dynamic SQL
          Introduction
          Using sp_executesql
          Using the CLR
          Using EXEC()
          When Caching Is Not Really What You Want
       Static SQL
          Introduction
          x = @x OR @x IS NULL
          Using IF statements
          Umachandar's Bag of Tricks
          Using Temp Tables
          x = @x AND @x IS NOT NULL
          Handling Complex Conditions
       Hybrid Solutions – Using both Static and Dynamic SQL
          Using Views
          Using Inline Table Functions
       Conclusion
       Feedback and Acknowledgements
       Revision History
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello Ruby/Rails/Merb developers! Im currently working on a web project that will have a
I have a web project working perfecly on my web server and on my
I'm working on a web project, which have to process so many client requests.
I have web application Project having RPC call. one RPC async is working fine.
I'm working on a larger Web based Project, that probably will have to handle
I'm working on a project where we have several SOAP Web Services developed on
I'm working on a project where we have jobs submitted via a web interface
I'm working on a GWT project, in which I have to fetch some JSON
I'm working on a little web-project-management-application. I have a few classes like Clients(), Services(),
I have been working on a web project that stores locations for users. The

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.