Solved

SQLServer and if/case in where clause

Posted on 2011-09-22
2
573 Views
Last Modified: 2012-05-12
Have a stored proc for displaying customer info which appears as:
create proc custinfo @nonzero smallint as
select * from customer
where...

The parm @nonzero (1 or 0) limits the display of customer's balances.  If
@nonzero = 1 then only customers with balances <> 0 display.  Otherwise
all customers display.

My issue is how best to express the where clause to accomodate @nonzero.

Currently I have: ((@nonzero = 1 and balance <> 0) or (@nonzero = 0)).  Surely there's a
better solution.
0
Comment
Question by:hawand5
[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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 36579748
your way is ok. there are alternatives (dynamic sql is the simple one, writing a different select for each case another one), all with other drawbacks.
0
 
LVL 6

Assisted Solution

by:kswathi
kswathi earned 125 total points
ID: 36579782
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CentOS Backup Options 3 66
SSIS - how to skip a step if it is spinning indefinitely in a step? 14 41
sql views 3 57
Oracle SQL-Queries on a RAC Database 3 47
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

751 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