Rabu, 16 November 2016

Re: [MS_AccessPros] Will Like '*' return records if the value is null?



That begs the question why you're applying any filter at all.  When you do Field LIKE "*", you force a table scan, which if you have a lot of records will be inefficient.  You say you're building the SQL in VBA.  Why include any predicate at all if the user specified no filter on the field?  I assume at the moment you're testing for empty criteria and sticking in LIKE "*" when there is none.  Don't do that.

John Viescas, Author
Effective SQL
SQL Queries for Mere Mortals 
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
(Paris, France)

On Nov 16, 2016, at 6:37 PM, winberry.doyce@con-way.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

Hello Pros,

I'm building a query on the fly through VBA and if appears that if the values for a field are null, the query won't return the record using criteria Like '*' for the field. Is that a correct? Here is the SQL of the query:

WHERE (((qS.MSDSID) Like '*') AND ((qS.ProductName) Like '*') AND ((qS.Category) Like '*') AND ((qS.MName) Like '*') AND ((qS.ChemTrekNo) Like '*') AND ((qS.PartNO) Like '*'));

In my table there are only 6 records and ChemTrekNo is null for all 6. Using Like '*' as criteria for ChemTrekNo no records are returned. What do I do if I want the records that contain nulls? Wrap it in Nz? What would the SQL look like?



Posted by: John Viescas <johnv@msn.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (2)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.



Tidak ada komentar:

Posting Komentar