Solved

Having vs Where

Posted on 2004-04-03
9
192 Views
Last Modified: 2009-12-16
Hi,

I know the basic difference between HAVING and WHERE.  In terms of the speed, does it make a difference?  Thanks
0
Comment
Question by:mcrmg
  • 4
  • 4
9 Comments
 
LVL 54

Expert Comment

by:nico5038
ID: 10751216
Hmm, I think not, but Access surprised me more then once :-)

Just create a small test module to execute a HAVING and a WHERE groupby query a few 1,000 times in a loop with a save time and a print of the time difference when ready.
Make sure to run it several times as the system's workload can make a single measurement unreliable.

Nic;o)
0
 

Author Comment

by:mcrmg
ID: 10751266
I was wondering if you could help me with this.  Thanks
0
 
LVL 54

Accepted Solution

by:
nico5038 earned 180 total points
ID: 10751295
Where's the problem?

Just create a function like:

Function fncTestTime()

Dim dtm As Date

dtm = Time()

For intI = 1 To 1000
   CurrentDb.Execute ("having query")
Next

Debug.Print "Having duration: " & Date - dtm

dtm = Time()

For intI = 1 To 1000
   CurrentDb.Execute ("where query")
Next

Debug.Print "Where duration: " & Date - dtm

End Function


Nic;o)
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:mcrmg
ID: 10751297
I was missing the "duration" Part...  Thank you
0
 

Author Comment

by:mcrmg
ID: 10751319
Hi,

I run this and it says " expect a function or variable", I thought I need to assign it to a rs??

Set rs = CurrentDb.Execute("SELECT * FROM Loan")
0
 
LVL 54

Expert Comment

by:nico5038
ID: 10751329
Try just:

 CurrentDb.execute("SELECT * FROM Loan")

Nic;o)
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 100 total points
ID: 10752060
I think this won't work. You can not execute a select query

       <CurrentDb.execute("SELECT * FROM Loan")>

Try it this way
Dim strSQL as String
strSQL="Select * From Loan"

Set rs = CurrentDb.OpenRecordset(strSQL)

0
 

Author Comment

by:mcrmg
ID: 10752160
Yes, it works fine.  How can I call a query that I built in query builder?  Thx
0
 
LVL 54

Expert Comment

by:nico5038
ID: 10752241
Just use the name in:
Set rs = CurrentDb.OpenRecordset("<queryname>")

Nic;o)
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question