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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:28:48+00:00 2026-06-10T18:28:48+00:00

please check below query DECLARE @status varchar(1) DECLARE @code varchar(50) Set @status = ‘0’

  • 0

please check below query

DECLARE @status varchar(1)
DECLARE @code varchar(50)

Set @status = '0'

select id,code from MasterTable where 
('07/31/2012' between  StartDate and EndDate) and 
Case when @status = '0' and Status=@status then 1 end = 1 

this query works for me, but not work for @Status=1

I need query like

if @Status = '0'
    select id,code from MasterTable where 
   ('07/31/2012' between  StartDate and EndDate) and Status = @Status
   if @code <> '0' 
        select id,code from MasterTable where 
        ('07/31/2012' between  StartDate and EndDate) and Status = @Status and code =@code
else
     select id,code from MasterTable where 
   ('07/31/2012' between  StartDate and EndDate) 
      if @code <> '0' 
        select id,code from MasterTable where 
        ('07/31/2012' between  StartDate and EndDate) and Status = @Status and code =@code     

How can I achieve this using case when statement ?

  • 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-10T18:28:49+00:00Added an answer on June 10, 2026 at 6:28 pm

    You can simplify the query by rephrasing it slightly:

    select  id,code 
    from    MasterTable 
    where   '07/31/2012' between  StartDate and EndDate)
            and (@status <> '0' or Status = @status)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please check below query. declare @xmlRoot as xml set @xmlRoot= '<Root> <table1 col1=2012-03-02T16:42:55.777> <table2Array>
Please check below table : Id Code Name State District Status ----------------------------------------------------------- 1 10001
I had a weird problem here. Please check the code below. I do not
guys please check my codes in displaying record.. <?php include(db.php); $username=$_POST['username']; $email=$_POST['email']; $query=SELECT *
Below query is resulting NO rows lstResults.RowSource = select EmpId from tblTesting where Empid
I am stuck in swich case. Please check code below Log.e(@@@@@@@@@@@@@@@@@@@@@ pos,+posSel_lay); String ff=Integer.toString(posSel_lay);
please check the HTML code below. The 3rd DIV is partially visible because it
Folks, Please check my code..am executing the below code by http://localhost/mycart/login.php?is_ajax=1&username=srini&password=srini Then am getting
Please check below screen shot. What is main difference between Master Page and MVC
Please check my HTML below: <table cellpadding=0 cellpadding=0 border=0> <tr> <td> <div class=toogler>Demo1</div> </td>

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.