473,405 Members | 2,154 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,405 software developers and data experts.

Improve query performance?

255 100+
From the below SQL statement, can anyone tell me any methods to improve it? As this query has keep running without results in my latest try, I have to break the process as it takes too long (waited 30 mins) to run.

Expand|Select|Wrap|Line Numbers
  1. SELECT A.USERNAME
  2. , A.ALARMDATE
  3. , Mid(A.ALARMDETAILS,(InStr(1,A.ALARMDETAILS,"User",1)+4),(InStr(InStr(1,A.ALARMDETAILS,"User",1),A.ALARMDETAILS,"(",1))-(InStr(1,A.ALARMDETAILS,"User",1)+4)) AS SC
  4.  
  5. FROM alarmManfASQueryA AS A, Employees AS E
  6.  
  7. WHERE (((A.USERNAME) Not Like '') 
  8. AND ((A.ALARMDATE) In (SELECT Max(B.ALARMDATE) FROM alarm AS B where (A.USERNAME = B.USERNAME) GROUP BY B.USERNAME) 
  9. And (A.ALARMDATE)>=DateSerial(Year(Date()),Month(Date()),Day(Date())-240)) AND ((A.ALARMDETAILS) Like "*Access Granted*"));
The alarmManfASQueryA is another query that generates around 110k records from an external database, but this takes only a few minutes to run.

The selected field "SC", is the key field required in further codings, its simply getting a number from A.ALARMDETAILS with below example.
Expand|Select|Wrap|Line Numbers
  1. Chall 1 (XXX) Access Granted with Region: Section 17 (Exit), Region 1 (region 1) (Jackie Chan, User 218)
The Mid(InStr(InStr))function will get the number 218 for SC.

Anyone can help would greatly appreciate. Thanks.


Update: I spend an hour time waiting to its completion, and yes the result appears 1 hour later. But this shouldn't be the time taken for this result, and Access crashed up when I tried to scroll down the list...
Sep 21 '10 #1
1 2002
code green
1,726 Expert 1GB
Sub-queries are usually the culprit but it looks like you are returning a huge recordset.
Start by converting this cartesian JOIN to a more specific one
Expand|Select|Wrap|Line Numbers
  1. FROM alarmManfASQueryA AS A, Employees AS E 
  2.  
Using the syntax
Expand|Select|Wrap|Line Numbers
  1. FROM alarmManfASQueryA AS A JOIN Employees AS E ON (A.field = E.field) 
  2.  
Then check how many records and the execution time of each sub-query, to see if that is as expected.
Sep 21 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: inna | last post by:
Hello. I have query performance question. I need to optimize procedure CREATE PROCEDURE dbo.SECUQUSRCOMPACCES @P1 VARCHAR(50), @P2 INTEGER AS DECLARE @IORGANIZATIONID INTEGER EXECUTE...
3
by: Leader | last post by:
Hi All, I am getting slower performance of select statements in MS SQL. I am finding select statements in MS SQL are even slower than MS ACCESS. Is there any way to improve the performance of...
8
by: Együd Csaba | last post by:
Hi All, how can I improve the query performance in the following situation: I have a big (4.5+ million rows) table. One query takes approx. 9 sec to finish resulting ~10000 rows. But if I run...
7
by: Bing Wu | last post by:
Hi Folks, I have a very large table containing 170 million rows of coordinats: CREATE TABLE "DB2ADMIN"."COORDINATE" ( "FID" INTEGER NOT NULL , "AID" INTEGER NOT NULL , "X" REAL NOT NULL ,...
2
by: Robert Stearns | last post by:
I am currently using the following query to select rows for a report. It takes forever, even though there are < 100 rows in the result set; The problem is that animals, epd and ent_herdid are all...
1
by: Hendry | last post by:
i want insert many rows into a table use javascript, but it was too slow when i insert 50 by 50 how can i improve the performance.
9
by: db2udbgirl | last post by:
Is this possible to tune this query further : Env : DB2 UDB 8.2 on AIX 5.3, Non partitioned tables Query: SELECT ETL.T00601.* FROM ETL.T00601, ETL.STG_LAAM_CARD20_BUS_ASCT_BUS_FCN where
4
by: traceable1 | last post by:
I am trying to improve the performance of a query. No matter how bad it runs the first time, it runs really fast the second time. So how can I tell if I've done anything to improve the query if...
2
by: Brian Tabios | last post by:
Hello Everyone, I have a very complex performance issue with our production database. Here's the scenario. We have a production webserver server and a development web server. Both are running...
5
by: wugon.net | last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad query performance Env: db2 LUW V8 + FP14 Problem : We have history data from 2005/01/01 ~ 2007/05/xx in single big...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.