?
Solved

SQL And....or....OR

Posted on 2011-03-17
2
Medium Priority
?
281 Views
Last Modified: 2012-05-11
I have a table that I've partitioned by claim_id.  I'm comparing fields from one partition to another and if they are different I want them in the result set.  

So in my WHERE clause, I have:

Where c1.Total <> c2.Total

BUT...if C1.Total <> c2.Total is not satisfied, I also want to see if there are other conditions met....and in the case where both are satisfied, I only want to return the record once, not twice.

Here would be an example
Claim_ID          Status         Total_Paid        Incurred_Amount      Eval_Date
1                      Open          100                   100                           12/31/2009
1                      Closed        100                   100                           12/31/2010

In the case above, Total_Paids for Claim_Id is equal so the first condition in my Where clause will not be satisfied, but I also want to pull claims where eval_date = 12/31/2009 and status = Open.  

What would SQL look like for that case?

I think the partition is throwing me off....I just want to return a record once if any one of my conditions are met...

I know how many records should be returned, but it seems my results are returning double records.  SQL is attached.



Sample-SQL.txt
0
Comment
Question by:tobin46
[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 2

Accepted Solution

by:
EL_Barbado earned 2000 total points
ID: 35162063
I don't see "Where c1.Total <> c2.Total" in the sql that you've attached. However, based on your earlier description I think what you intend to do is:

Where (c1.Total <> c2.Total) OR (eval_date = 12/31/2009 AND status = Open)
0
 
LVL 9

Expert Comment

by:rajeevnandanmishra
ID: 35164253
Hi,

With the query in thread ID:
please change the Order By in your CTE as
ORDER BY Policy_Number, [Claim#], claim_id, Valuation_Date

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

752 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