[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SQL Case question

Posted on 2013-01-30
2
Medium Priority
?
272 Views
Last Modified: 2013-01-31
Hi

I have an sql query with a few parameters. If one of these parameters is 0 I want to use a different where clause.


I'd to this like this

If @Param = 0
  Begin
    --SQL here with where clause
  End

Else

  Begin
    --SQL here with another where clause
  End

My question is this, can this be done in a single SQL statement with say a CASE When in the where clause?

Andy
0
Comment
Question by:Andy Green
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 total points
ID: 38837415
SELECT ..
FROM ..
WHERE (@param = 0 and somethingElsse = someotherValue ) or
 ( (@param <> 0 and  SomeOtherCondition )
0
 
LVL 3

Author Closing Comment

by:Andy Green
ID: 38838712
Thats is so cool (& simple). Gonna be using it again.

Thanks
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question