DCOUNT vs SQL

J

JethroUK©

1/ which is faster, retrieving value via DCount or SQL?

2/ how often is a form value re-calculated - i.e. if i have a textbox that
returns Dcount which is populated on form load - how often is the value
refreshed? or is it static until i refresh it myself?
 
R

Rick Brandt

JethroUK© said:
1/ which is faster, retrieving value via DCount or SQL?

First explain how you would use SQL. If you need a single value (likely when
talking about a "count") and by "SQL" you mean creating a RecordSet in code and
then retrieving the value from that RecordSet then there shoudl not be much
difference.

DCount() and the other domain functions are not good performers in queries or
code looping procedures because they incur some system overhead each time they
are called. SQL and Recordsets are better in these cases but ONLY if built and
used in a manner that avoids that same overhead that the domain functions have.
2/ how often is a form value re-calculated - i.e. if i have a textbox
that returns Dcount which is populated on form load - how often is
the value refreshed? or is it static until i refresh it myself?

A DCount expression on a form would generally refresh itself each time you
changed to a different record. Otherwise you would need to refresh it yourself.
 
J

JethroUK©

i understand DCOUNT is very slow - especially since you say it's
recalculated every record change (more frequent than i need)

so i'm wondering whether it would perform better to populate the box using
sql (currentdb.execute 'SELECT Count(ID)....' ) - which need only be
refreshed after an update

i'll try both and see which works best

thanks
 
A

Albert D.Kallal

i understand DCOUNT is very slow - especially since you say it's
recalculated every record change (more frequent than i need)

Actually, to clarify what is being said:

dcount() does NOT perform any faster, or slower then the use of a query (ie:
some code, and a query to create a recordset, and then grab the value).

dcount() is revaluated every record, but only when you use it as such. So,
if you open to one form that displays one record, then dcount() does not
just start re-calculation blindly here. However, the point mentioned that it
is so EASY TO use dcount() in all kinds of places, and that is WHEN it hurts
performance. So, it is not the fact of it being slower, or faster then you
using a query, but WHERE and HOW you use it.

So, if you have a continues form, and place dcount() in the sql query, or
even bound as a expression to a text box, and that form displays 20 records
in continues mode, then you fire off that expensive dcount() function 20
times.

For the most part, you as the developer has control over this, so, the
suggestion here is that dcount() vs a query is not slower, but you tend to
hang yourself by using dcount() because it can be used a expression in all
kinds of places with such great ease. It is the "ease" of use that hurts
performance....not the fact that dcount() runs slower then building a query
to do the same. (as mentioned, they run the same speed).

If you removed that dcount() from the continues form, and replaced it with a
function that calls your code that executes the query for each record, you
would find this is just as slow (in fact, I would bet it would be *slower*
then dcount() ).

You can usually eliminate the dcount() in that continues form by using a
sub-query in the original sql. This will run MUCH faster then dcount() or
your code since the query only needs to be "setup" and compiled once....
 
M

Marcin

U¿ytkownik "JethroUK© said:
1/ which is faster, retrieving value via DCount or SQL?

2/ how often is a form value re-calculated - i.e. if i have a textbox that
returns Dcount which is populated on form load - how often is the value
refreshed? or is it static until i refresh it myself?

============================================================================
================
FULL LEGAL SOFTWARE !!!
Games, video, program, image, chat, questbook, catalog site, arts, news,
and...
This site it is full register and legal software !!!
Please download and you must register software !!!

PLEASE REGISTER SOFTWARE:
http://www.webteam.gsi.pl/rejestracja.htm
DOWNLOAD LEGAL SOFTWARE:
http://www.webteam.gsi.pl

Full question and post: http://www.webteam.gsi.pl

Contact and service and advanced technology:
http://www.webteam.gsi.pl/kontakt.htm
FAQ: http://www.webteam.gsi.pl/naj_czesciej_zadawane_pytania.htm

Please add me URL for you all site and search engines and best friends !!!

Me site:
SERWIS WEBNETI: http://www.webneti.gsi.pl
PORTAL WEBTEAM: http://www.webteam.gsi.pl
LANGUAGE: http://www.webneti.cjb.net
============================================================================
================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

DCount alwaysreturning 1 0
dcount() query 1
Help with DCOUNT syntax 2
DCount 1
DCount vs something better? 6
Dcount help 1
Get dates from table where month and year like txtbox 5
problem with DCount 3

Top