Solved

Using CASE in WHERE Clause

Posted on 2010-11-09
3
256 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help  needed 3 35
SQL Server 2012 r2 - Query results have 2 seperate results instead of 1 2 31
Query group by data in SQL Server - cursor? 3 47
Job - date manual 1 35
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…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 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