Help on a SQL query

Need some help on a query, I don't want to change query significantly. I am trying to list only records that do not have a statusid of 10. Also I do not want to list records that have a statusid of 17 where modifieddate is more than 6 months past. How to do this? The following query does not work the way I want it to.

var q = from tList in targetList
                      where (tList.Status.StatusID != 10) && (tList.Status.StatusID != 17 && tList.Modified > date6MonthsPast)
                       select tList;

Open in new window

LVL 1
mathew_sAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

grendel777Commented:
It sounds like you just need to change the operator between your statements to an OR instead of AND. That is, you want to exclude if (not = 10) OR (not old):
var q = from tList in targetList
                      where (tList.Status.StatusID != 10) || (tList.Status.StatusID != 17 && tList.Modified > date6MonthsPast)
                       select tList;

Open in new window

mathew_sAuthor Commented:
Tried that but now I am seeing records where status =10 and I don't want that. I don't want any records of status =10 AND only records of status=17 where modifieddate is more than 6 months past
jcgdCommented:
(tList.Status.StatusID != 10) && not (tList.Status.StatusID == 17 && tList.Modified > date6MonthsPast)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Deepak ChauhanSQL Server DBACommented:
Here is the SQL systax , you can change it according to your code

select * from (
select status.statusid,tList.Modified   from tlist 
where tList.Status.StatusID != 10
except
select statusid, Modified   from tlist 
where StatusID = 17 and Modified > date6MonthsPast)) Tlist

Open in new window

awking00Information Technology SpecialistCommented:
I think the except method will work without the subquery -
select * from tLIst where StatusID != 10
except
select * from tLIst where StatusID = 17 and Modified > date6MonthsPast
mathew_sAuthor Commented:
This worked just had to change to (tList.Status.StatusID != 10) && !(tList.Status.StatusID == 17 && tList.Modified < date6MonthsPast)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.