Solved

SQL Case question

Posted on 2013-01-30
2
262 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 500 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
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 setup several different housekeeping processes for a SQL Server.

690 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