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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:28:13+00:00 2026-06-02T16:28:13+00:00

Apologies for creating a new thread. I was not able to frame the question

  • 0

Apologies for creating a new thread. I was not able to frame the question correctly in the previous thread.

I have a table in SQL Server 2008 that looks like this –

Id      Status
--------------
1        A
2        I
3        NULL

I have a stored procedure which takes @Status as the parameter.

If the @Status is "-1", I need to retrieve records 1, 2. 
If the @Status is "A", I need to retrieve only record 1.
If the @Status is "I", I need to retrieve only record 2.

I want to be able to retrieve the records in a single SELECT statement without using IF ELSE. There are a lot of joins and stuff in the SELECT statement and I don’t want to repeat the same thing in the ELSE condition.

I have tried the following but get incorrect data –

SELECT * FROM Person WHERE Status = @Status OR @Status IS NOT NULL

select * from Person
where (@Status is not null and Status = @Status) or
      (@Status is null and Status in ('A', 'P')) 
  • 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-02T16:28:15+00:00Added an answer on June 2, 2026 at 4:28 pm

    You can do it using OR:

    SELECT *
    FROM Person
    WHERE Status = @Status
    OR (@Status = '-1' AND Status IS NOT NULL)
    

    Of course you shouldn’t use SELECT * in production code.

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

Sidebar

Related Questions

(First question related to iPhone development, so apologies for sounding off-track.) I'm creating a
Apologies in advance for the long-winded question. I'm really a database programmer, but have
Apologies if this is a dumb question. In previous ASP.NET projects, I've been using
Apologies in advance, am fairly new to rails. Creating a site to showcase cooking
I have a small doubt, so apologies first. I am creating an iPhone application
Apologies as I'm relatively new to Spring. I have the following code... org.assessme.com.dao.UserDAOImpl.java @Repository
First of all, apologies for not being able to supply any sourcecode. My project
Apologies if this is too ignorant a question or has been asked before. A
Apologies if this question is a bit obscure, I've been banging my head against
Apologies if this is a repost, I could not find the search terms to

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.