Domanda

I have a table called VHS_Metadata_Aug52014 with columns:

Title, Description,Tag, Speaker, VIP, FilmingLocation, Notes

I'm trying to write a query that returns all records for which the word "News" is not in any value. There are indeed records of this type. However, the query below returns nothing. So, I'm guessing I'm not quite understanding how to do it. I'm using MS Access, where the wildcard is *.

UPDATE: I just tried also using the syntax:

Not VHS_Metadata_Aug52014!Description like '*News*'

And I'm still getting no hits.

select * from VHS_Metadata_Aug52014 where (
VHS_Metadata_Aug52014!Title Not like '*' & 'News' & '*'
And
VHS_Metadata_Aug52014!Description Not like '*' & 'News' & '*'
And
VHS_Metadata_Aug52014!Tag Not like '*' & 'News' & '*'
And
VHS_Metadata_Aug52014!Speaker Not like '*' & 'News' & '*'
And  
VHS_Metadata_Aug52014!VIP Not like '*' & 'News' & '*'
And
VHS_Metadata_Aug52014!FilmingLocation Not like '*' & 'News' & '*'
And
VHS_Metadata_Aug52014!Notes Not like '*' & 'News' & '*'
) ;
È stato utile?

Soluzione

The problem is most likely some NULL values. Unfortunately, NULL LIKE 'anypattern' will not result in FALSE but in UNKNOWN and NOT UNKNOWN is still UNKNOWN. So any row where one or more of the values is Null, will not be in the result list because WHERE filters all rows that the condition is anything but TRUE (FALSE and UKNOWN get rejected).

Try this change:

select * from VHS_Metadata_Aug52014 where 
(Title Not like '*' & 'News' & '*'           Or Title Is Null)
And
(Description Not like '*' & 'News' & '*'     Or Description Is Null)
And
(Tag Not like '*' & 'News' & '*'             Or Tag Is Null)
And
(Speaker Not like '*' & 'News' & '*'         Or Speaker Is Null)
And  
(VIP Not like '*' & 'News' & '*'             Or VIP Is Null)
And
(FilmingLocation Not like '*' & 'News' & '*' Or FilmingLocation Is Null)
And
(Notes Not like '*' & 'News' & '*'           Or Notes Is Null)
;

Altri suggerimenti

For Microsoft SQL Server, MySQL, PostgreSQL, etc the wildcard is not * but is %.

If you search for "wildcards" in your SQL documentation you should find your particular server's supported wildcards.

EDIT: Post comment: Sorry, I have never written MS Access queries.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a dba.stackexchange
scroll top