473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Query runs extremely slow because of simple user defined function

I have a query that just reads one table and appends to an output
table, one-for-one. No criteria. It's not a Total query (i.e. no
group by). It normally run run in minutes, but gets horribly slowed
down because five of my output fields are text fields and the
expression that gets appended is a user-defined function I wrote which
is very simple (just a few lines long). Here's the code of my
function:

Public Function tformat(num As Double, xdec As Byte) As String
If xdec = 0 Then
tformat = Right(Space(12) + Format(num), 12)
Else
tformat = Right(Space(12) + Format(num, "0." + String(xdec,
"0")), 12)
End If
End Function

In each of the 5 expressions in my query grid, the parameters I pass
are:
num: a numeric field from the query's input table
xdec: a numeric literal constant.
The above function looks fairly simple, but it causes my query which
otherwise would run in a few minutes to take many times that long to
finish (maybe an hour). Do any of you understand why, or maybe have a
helpful suggestion about a trick I could use to speed up my query?
Nov 12 '05 #1
2 8192
I'd be interested to see the SQL behind your query, that may have something
to do with it.

Assuming however that this is a VBA problem - given what your function
actually does I think the best way to do this would be to do away with the
custom function altogether and do the whole thing in SQL using an IIf
statement.
IIf(xdec=0,Right(Space(12)+Format([num]),12),Right(Space(12)+Format([num],"0
.."+String(xdec,"0")),12))

(remembering of course to replace the xdec with your literal)

May work, may not work, suck it and see...

"Mrs Howl" <ti********@yahoo.com> wrote in message
news:5b*************************@posting.google.co m...
I have a query that just reads one table and appends to an output
table, one-for-one. No criteria. It's not a Total query (i.e. no
group by). It normally run run in minutes, but gets horribly slowed
down because five of my output fields are text fields and the
expression that gets appended is a user-defined function I wrote which
is very simple (just a few lines long). Here's the code of my
function:

Public Function tformat(num As Double, xdec As Byte) As String
If xdec = 0 Then
tformat = Right(Space(12) + Format(num), 12)
Else
tformat = Right(Space(12) + Format(num, "0." + String(xdec,
"0")), 12)
End If
End Function

In each of the 5 expressions in my query grid, the parameters I pass
are:
num: a numeric field from the query's input table
xdec: a numeric literal constant.
The above function looks fairly simple, but it causes my query which
otherwise would run in a few minutes to take many times that long to
finish (maybe an hour). Do any of you understand why, or maybe have a
helpful suggestion about a trick I could use to speed up my query?

Nov 12 '05 #2
False alarm... I've figured it out. If the visual basic window is
open while the query is running, it drastically slows down the query.
I aborted the query, close the visual basic window and reran. It ran
much faster. Why this should make a difference, I don't know.
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Robert | last post by:
I am having performance issues on a SQL query in Access. My query is accessing and joining several tables (one very large one). The tables are linked ODBC. The client submits the query to the...
3
by: Janross | last post by:
I'm having trouble with a query that's prohibitively slow. On my free-standing office computer it's fine (well, 2-4 seconds), but on the client's network, it takes at least 5 minutes to run. ...
15
by: Rolan | last post by:
There must be a way to enhance the performance of a query, or find a plausible workaround, but I seem to be hitting a wall. I have tried a few tweaks, however, there has been no improvement. ...
12
by: strict9 | last post by:
Hello all, I'm writing several queries which need to do various string formating, including changing a phone number from (123) 456-7890. After some problem with data mismatches, I finally got it...
6
by: Greg Strong | last post by:
Hello All, In an 'Update' query can you use user-defined functions in the 'Update To' for the query? Either no or I'm missing something. See the additional info below. If I run a query...
11
by: Andy_Khosravi | last post by:
My problem: I'm having trouble with a query taking much too long to run; a query without any criteria evaluating only 650 records takes over 300 seconds to run (over the network. On local drive...
29
by: wizofaus | last post by:
I previously posted about a problem where it seemed that changing the case of the word "BY" in a SELECT query was causing it to run much much faster. Now I've hit the same thing again, where...
2
by: Himmel | last post by:
Hello! The reference database I currently use runs queries that pull data from hundreds of tables in order to create user-friendly form view. The problem is that these queries can take upwards of...
1
by: hedgracer | last post by:
have a query that has a <>0 in a summed number field. The query runs extremely slow (30+ seconds) when this parameter is in this field. If I eliminate this parameter the query runs in milliseconds....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.