Link to home
Start Free TrialLog in
Avatar of John Ellis
John Ellis

asked on

T-SQL: Eliminating Records Based on Criteria

Hello:

Please review the screenshot embedded at the end.

I want to eliminate records where [DaysLate] > 0 but only where [DocumentType] is not in 'Scheduled Payments', 'Credit Memo', 'Return', or 'Payment'.

I did not know what to do but to use the clause shown below that is above my screenshot.  

But, when I do this, SQL eliminates all records of 'Scheduled Payments', 'Credit Memo', 'Return', 'Payment'.  I want to keep all of those records.  

As far as other records are concerned, I want them gone if they are 0 or less.

How can I make this happen?

Thanks!

John

HAVING (CASE WHEN [DocumentType] not in ('Scheduled Payments', 'Credit Memo', 'Return', 'Payment') THEN [DaysLate] ELSE 0 END) > 0

Open in new window


User generated image
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial