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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:27:28+00:00 2026-06-06T01:27:28+00:00

I am writing a stored procedure with 3 parameters and my where clause changes

  • 0

I am writing a stored procedure with 3 parameters and my where clause changes depending on one of these parameteres. Is it possible to write a SQL query in this way –

    CREATE PROCEDURE [dbo].[VendorVettingModal] @column NVarchar (50), @applicanttype NVarchar (10), @donotuse int AS

                declare @column NVarchar (50), @applicanttype NVarchar (10), @donotuse int

    select a.Id, a.Firstname, rs.Status,cs.ClearanceStatus
    from applicant a 
    left join ReviewStatus rs on a.ReviewStatus = rs.Id 
    left join ClearanceStatus cs on a.ClearanceStatus = cs.Id
    where
    if(@column = 'Recruiting')
    begin
        a.applicanttype = @applicanttype and a.reviewstatus = 7 and a.donotuse = @donotuse      
    end
    else if(@column = 'Clearance')
    begin
        a.applicanttype = @applicanttype and (a.reviewstatus != 7 or a.reviewstatus is null) and a.donotuse = @donotuse     
    end 

Rather than writing this way? Because I have about 20-25 columns and a lot more joins and where params than defined here. I have just tried to make it less complicated here.

    CREATE PROCEDURE [dbo].[VendorVettingModal] @column NVarchar (50), @applicanttype NVarchar (10), @donotuse int AS

                declare @column NVarchar (50), @applicanttype NVarchar (10), @donotuse int

    if(@column = 'Recruiting')
    begin
        select a.Id, a.Firstname, rs.Status,cs.ClearanceStatus
        from applicant a 
        left join ReviewStatus rs on a.ReviewStatus = rs.Id 
        left join ClearanceStatus cs on a.ClearanceStatus = cs.Id
        where
        a.applicanttype = @applicanttype and a.reviewstatus = 7 and a.donotuse = @donotuse      
    end
    else if(@column = 'Clearance')
    begin
        select a.Id, a.Firstname, rs.Status,cs.ClearanceStatus
        from applicant a 
        left join ReviewStatus rs on a.ReviewStatus = rs.Id 
        left join ClearanceStatus cs on a.ClearanceStatus = cs.Id
        where
        a.applicanttype = @applicanttype and (a.reviewstatus != 7 or a.reviewstatus is null) and a.donotuse = @donotuse     
    end 
  • 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-06T01:27:29+00:00Added an answer on June 6, 2026 at 1:27 am

    Use parenthesis:

     select a.Id, a.Firstname, rs.Status,cs.ClearanceStatus
        from applicant a 
        left join ReviewStatus rs on a.ReviewStatus = rs.Id 
        left join ClearanceStatus cs on a.ClearanceStatus = cs.Id
        where a.applicanttype = @applicanttype
        and a.donotuse = @donotuse 
        AND ((@column = 'Recruiting' AND (a.reviewstatus = 7))
        OR
        (@column = 'Clearance' AND (a.reviewstatus != 7 or a.reviewstatus is null)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

please help me with writing this search sql stored procedure procedure may have different
I am new to writing Stored Procedure. So I wrote one with output parameters
I am writing a stored procedure in SQL Server 2008. Here I have a
I'm new to this. I'm writing a clr stored procedure that calls another stored
Okay so I'm writing a SQL Server 2008 Stored Procedure (maintenance script). In doing
I am writing a Stored procedure in SQL Server 2008. I need to check
This is my first shot at writing a stored procedure. I'm trying to get
Writing a stored procedure that will have multiple input parameters. The parameters may not
When writing Java stored procedures, I often receive values via oracle.sql.ARRAY parameters. However, how
Writing a stored procedure in MS SQL Server 2008 R2, I want to avoid

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.