?
Solved

SQL Case question

Posted on 2013-01-30
2
Medium Priority
?
267 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Suggested Courses

765 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