Solved

Using CASE in WHERE Clause

Posted on 2010-11-09
3
254 Views
Last Modified: 2012-05-10
Hello I have the following code in my WHERE clause

AND
(
     ISNULL(m.Member,'FALSE') = 'TRUE'
     OR
     (
          ISNULL(vc.Amount,0) != 0
          AND vc.VoluntaryContributionTypeID = @contribtuionTypeID
     )
)

This works really well. However I've now been giving some additional requirements and I'm ot sure how to make the SQL work.

If a varialbe called TypeID (not shown in above code) is = 1, then I don't want the clause to evaluate this portion:

ISNULL(m.Member,'FALSE') = 'TRUE'

So if TypeID is 1, I don't care about the n.Member field, if it is not 1, I do care.

Any easy way to write that statement?
0
Comment
Question by:WaldaInc
  • 2
3 Comments
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34097308
AND (
(typeid=1 OR Isnull(m.member,'FALSE')='TRUE') -- one of
OR
-- rest of clause
0
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
ID: 34097310
AND (
(typeid=1 OR Isnull(m.member,'FALSE')='TRUE') -- one of
OR
-- rest of clause
0
 

Author Closing Comment

by:WaldaInc
ID: 34207903
Thanks.

Worked fine once implemented.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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