Petrobras
asked on
Criteria Query: Not like
I have criteria in a query that I am having a problem with selecting all the records that I need. I need to exclude deals that have the status as "New Deals" and anything like "New Deals". I know that I can use something like <> "New Deals" &"*" but since I am exlcuding other criteria the <> "New Deals" &"*" does not seem to work.
What i have now:
<>"withdrawn" And <>"Funded" And <>"New Deals" And <>"New Deals on Hold"
Is there some way to exclude any deal that has a status of "New Deals" & "*"?
If I include the <> "New Deals" &"*" in the criteria then I get no hits and I should get a few. If I remove the <> "New Deals" &"*" and replace it with <>"New Deals" And <>"New Deals on Hold" then I get the hits I need.
thank you.
What i have now:
<>"withdrawn" And <>"Funded" And <>"New Deals" And <>"New Deals on Hold"
Is there some way to exclude any deal that has a status of "New Deals" & "*"?
If I include the <> "New Deals" &"*" in the criteria then I get no hits and I should get a few. If I remove the <> "New Deals" &"*" and replace it with <>"New Deals" And <>"New Deals on Hold" then I get the hits I need.
thank you.
If you try this ffrom a SQL point of view, I Think this should work:
SELECT * FROM Table WHERE FieldName NOT LIKE 'New Deals%' AND FieldName <> "Funded" AND FieldName <> "withdrawn"
SELECT * FROM Table WHERE FieldName NOT LIKE 'New Deals%' AND FieldName <> "Funded" AND FieldName <> "withdrawn"
NOT is a rather tricky way to get the information.
In general I specify a "positive selection" and after surrounding it by ( and ) then put NOT infront of it.
So try:
WHERE NOT ([Deals] like 'New deals*')
Nic;o)
In general I specify a "positive selection" and after surrounding it by ( and ) then put NOT infront of it.
So try:
WHERE NOT ([Deals] like 'New deals*')
Nic;o)
why not try a subquery?
not sure if that what Nico is talking about, something like this
select *
from table
where myfield <> "withdrawn"
and myfield <> "funded"
and mytable_id not in (select mytable_id where myfield like 'New Deals*')
alterntive apporach might be the IN command, not sure if you can use NOT with it
e.g.
select * from mytable where myfield IN ('funded','withdrawn','new deals','new deals on hold')
so with not try this
select * from mytable where myfield not IN ('funded','withdrawn','new deals','new deals on hold')
not sure if that what Nico is talking about, something like this
select *
from table
where myfield <> "withdrawn"
and myfield <> "funded"
and mytable_id not in (select mytable_id where myfield like 'New Deals*')
alterntive apporach might be the IN command, not sure if you can use NOT with it
e.g.
select * from mytable where myfield IN ('funded','withdrawn','new
so with not try this
select * from mytable where myfield not IN ('funded','withdrawn','new
ASKER
Nico,
I like your answer but I cant seem to get it to work. I am a novice at Access. I am not a programmer either. Is "Deals" the name of the fieldname? I put your statement in the criteria of the query on my form but gives me no hits.
thank you
I like your answer but I cant seem to get it to work. I am a novice at Access. I am not a programmer either. Is "Deals" the name of the fieldname? I put your statement in the criteria of the query on my form but gives me no hits.
thank you
Yes, [Deals] is what I interpreted as the name holding the values "New Deals", "New Deals on Hold", etc.
But I don't know the fieldname you use as it's not in your "WHERE" statement.
So lets assume it's [Status]. A "valid" WHERE would look then like:
WHERE [Status] <>"withdrawn" And [Status] <>"Funded" And [Status] <>"New Deals" And [Status] <>"New Deals on Hold"
or better:
WHERE NOT ([Status] IN ("withdrawn", "Funded", "New Deals", "New Deals on Hold") )
Having multiple different values for one field tested is best done using the "IN" and between the ( and ) a comma separated list of the values.
Can you give a list of all values you need to exclude and the fieldname from the table that hold these ?
Nic;o)
But I don't know the fieldname you use as it's not in your "WHERE" statement.
So lets assume it's [Status]. A "valid" WHERE would look then like:
WHERE [Status] <>"withdrawn" And [Status] <>"Funded" And [Status] <>"New Deals" And [Status] <>"New Deals on Hold"
or better:
WHERE NOT ([Status] IN ("withdrawn", "Funded", "New Deals", "New Deals on Hold") )
Having multiple different values for one field tested is best done using the "IN" and between the ( and ) a comma separated list of the values.
Can you give a list of all values you need to exclude and the fieldname from the table that hold these ?
Nic;o)
ASKER
Nico,
The way I have it written now after your last email is
WHERE NOT ([Status] IN ("Claim", "Denied", "Withdrawn", "Funded", "New Deals", "New Deals on Hold") )
but when I click out of the box it gives me an error "You may have entered an operator, such as the + operator, in an exporession without an operand.
thank you
The way I have it written now after your last email is
WHERE NOT ([Status] IN ("Claim", "Denied", "Withdrawn", "Funded", "New Deals", "New Deals on Hold") )
but when I click out of the box it gives me an error "You may have entered an operator, such as the + operator, in an exporession without an operand.
thank you
Can you post the complete query SQL text ?
Nic;o)
Nic;o)
ASKER
Nico,
it is big...
SELECT tblDeals.*, tblExporters.Name, tblLetterOfCredit.*, tblBrokers.Name, tblBorrower.Name, tblBorrower.APONumber FROM ((tblBorrower RIGHT JOIN (tblBrokers RIGHT JOIN tblDeals ON tblBrokers.BrokerID=tblDea ls.BrokerI D) ON tblBorrower.DealID=tblDeal s.DealID) LEFT JOIN tblLetterOfCredit ON tblDeals.DealID=tblLetterO fCredit.De alID) LEFT JOIN tblExporters ON tblDeals.DealID=tblExporte rs.DealID WHERE (((tblExporters.Name) Not Like Forms!frmReportsMain!NotLi ke) And ((tblDeals.Status)<>"Denie d" And (tblDeals.Status)<>"Claim" And (tblDeals.Status)<>"withdr awn" And (tblDeals.Status)<>"Funded " And (tblDeals.Status)<>"New Deals" And (tblDeals.Status)<>"New Deals - on Hold") And ((tblLetterOfCredit.LCFees Paid)=Form s!frmRepor tsMain!LCF eesPaid) And ((tblLetterOfCredit.[Polic yRec'd])=F orms!frmRe portsMain! PolicyRece ived) And ((tblLetterOfCredit.Arrang eFeePaid)= Forms!frmR eportsMain !ArrangeFe ePaid) And ((tblLetterOfCredit.Invoic edforLegal Paid)=Form s!frmRepor tsMain!Inv oicedforLe galPaid) And ((tblLetterOfCredit.Invoic edGoodFait hDepositPa id)=Forms! frmReports Main!Invoi cedGoodFai thDepositP aid)) ORDER BY tblBorrower.Name, tblDeals.Status DESC;
thank you
it is big...
SELECT tblDeals.*, tblExporters.Name, tblLetterOfCredit.*, tblBrokers.Name, tblBorrower.Name, tblBorrower.APONumber FROM ((tblBorrower RIGHT JOIN (tblBrokers RIGHT JOIN tblDeals ON tblBrokers.BrokerID=tblDea
thank you
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Well, I thank you for your help. I had problems with that too. I will continue with my old way.
thank you
thank you
Where are you running this SQL from?
Is it an object, or are you running from a form?
If it's from a form, you can use CASE to build your statement, based on the user selecting "Like" or "NOT LIKE" from a combo box or option list.
Idea?