Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not getting Results!!

Status
Not open for further replies.

kmkland

Technical User
Dec 15, 2004
114
0
0
US
I have created a statement using Not Like, but I am not getting the results that I need. Here's the code:
Code:
SELECT [tbl7-10Procedure].Date1Status, [tbl7-10Procedure].Date2Status, [tbl7-10Procedure].Date3Status, [tbl7-10Procedure].Date4Status
FROM [tbl7-10Procedure]
WHERE ((([Date1] & ' ' & [Date1Status]) Not Like "OK*")) OR ((([Date2] & ' ' & [Date2Status]) Not Like "OK*")) OR ((([Date3] & ' ' & [Date3Status]) Not Like "OK*")) OR ((([Date4] & ' ' & [Date4Status]) Not Like "OK*"))
GROUP BY [tbl7-10Procedure].Date1Status, [tbl7-10Procedure].Date2Status, [tbl7-10Procedure].Date3Status, [tbl7-10Procedure].Date4Status;
I want to get results that do not have "OK" in them. But instead, I'm getting all of the results. What should I change?!?
Thanks in advance!!

Rgds,
Kmkland
 
why are you combining your Date1 field with the Date1Status field?

Have you thought about normalizing your data to make this easier to accomplish?

I want to get results that do not have "OK" in them

specifically which field contains the OK? the Status field?

How's this:

Code:
SELECT [tbl7-10Procedure].Date1Status, [tbl7-10Procedure].Date2Status, [tbl7-10Procedure].Date3Status, [tbl7-10Procedure].Date4Status
FROM [tbl7-10Procedure]
WHERE ([Date1Status] Not Like "*OK*") OR ([Date2Status] Not Like "*OK*") OR ([Date3Status] Not Like "*OK*") OR ([Date4Status] Not Like "*OK*");

Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for anyone working with databases: The Fundamentals of Relational Database Design
 
Leslie, I had forgotten to remove the combined fields....
Now, I feel quite silly. :)

Unfortunately, I'm still getting the same results.


Rgds,
Kmkland
 


Check your BOOLEAN logic!
Code:
WHERE ([Date1Status] Not Like "*OK*") AND ([Date2Status] Not Like "*OK*") AND ([Date3Status] Not Like "*OK*") AND ([Date4Status] Not Like "*OK*");

Skip,
[sub]
[glasses] [red]Be Advised![/red] Dyslexic poets...
write inverse! [tongue][/sub]
 
Then, it will produce no results.

Rgds,
Kmkland
 
just to clarify, you want to return records where ANY of Date#Status fields DO NOT contain OK or ALL the Date#Status fields DO NOT contain OK.

which do you want?

Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for anyone working with databases: The Fundamentals of Relational Database Design
 
I need ALL of the fields that do not contain "OK".

Rgds,
Kmkland
 
so out of the following sample data, which records would you want to see? (if this data doesn't show what you are trying to do, feel free to provide some actual sample data and expected results to help us understand better)

ID Date1Stat Date2Stat Date3Stat Date4Stat
1 Bad Almost OK Good OK
2 Decent Not Good OK Bad
3 OK OK OK OK



Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for anyone working with databases: The Fundamentals of Relational Database Design
 
ID Date1Stat Date2Stat Date3Stat Date4Stat
1 Bad Good
2 Decent Not Good Bad


Rgds,
Kmkland
 
Something like this ?
SELECT ID
, IIf([Date1Status] Like 'OK*', '', [Date1Status]) AS Status1
, IIf([Date2Status] Like 'OK*', '', [Date2Status]) AS Status2
, IIf([Date3Status] Like 'OK*', '', [Date3Status]) AS Status3
, IIf([Date4Status] Like 'OK*', '', [Date4Status]) AS Status4
FROM [tbl7-10Procedure]
WHERE Date1Status & Date2Status & Date3Status & Date4Status Not Like 'OK*OK*OK*OK*'

Sorry Leslie ;-)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
i'm used to it, always know that as soon as I say something can't be done, you'll be right there proving me wrong!

That's why you're the SQL guru!!

have a great day!

les
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top