Solved

SQL filtering issue

Posted on 2014-09-26
3
377 Views
Last Modified: 2014-09-26
My WHERE clause in my query must have faulty logic.

WHERE (rems.project.hidden = 0) AND (NOT (rems.jobsalesexti.prodcode IN ('0000Base', 'ELEVA', 'ELEVB', 'ELEVC', 'EXTCOL'))) AND (rems.jobsalesexts.paycode = '') OR
               (rems.jobsalesexts.paycode = 'Draw 1')

Open in new window


The second part of my filter works but the first part is ignored. Is there a way to structure this so that I can get the desired result?
0
Comment
Question by:J C
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 500 total points
ID: 40346349
If your desire is not to bring back all paycodes equal to Draw 1, then place parentheses around the two paycode filters:
AND ((rems.jobsalesexts.paycode = '') OR (rems.jobsalesexts.paycode = 'Draw 1'))
0
 

Author Comment

by:J C
ID: 40346403
Right now the issue is that the filter expression with the OR operator is working but the prodcode IN () is being ignored. Do you see any reason why the filter expression as a whole would not work?
0
 

Author Comment

by:J C
ID: 40346432
I'm sorry...You're solution did resolve my problem. Thank you!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In this article I will describe the Copy Database Wizard 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.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now