473,511 Members | 15,503 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Please help speed up my query!


Hi there,

had to rush some sql and am now going back to it due to a slow db
performance. I have a db for sales leads and have created 3 views based
on the data I need to produce.

However one o the views, which has subqueries to the other views is VERY
slow and it needs to be speeded up, but am unsure how, can anyone
help... below is the sql?

SELECT CGAMain.CGAMainId,CGAMain.Salutation,CGAMain.First Name,

CGAMain.LastName,CGAMain.Salutation2,CGAMain.First Name2,CGAMain.LastName
2,
cgamain.telephone,CGAMain.[Post Code],
other.dbo.users.UserName, other.dbo.agents.[agent_name],
LEADSTATUS.CURRENTSTATUS,leadstatus.activestatus,L eadstatus.[no
answer],CGAMain.rescode,
Agent_displayname As 'Called By'
FROM Leadstatus INNER JOIN CGAMain ON Leadstatus.CGAMainId =
CGAMain.CGAmainId
INNER JOIN other.dbo.users ON Leadstatus.LTAid = other.dbo.users.userref
INNER JOIN other.dbo.agents ON Leadstatus.agentid = other.dbo.agents.id
WHERE
(StatusAssigned = 1)
AND (leadstatus.activestatus = 'Active')

please help???

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
2 1913
m3ckon (an*******@devdex.com) writes:
had to rush some sql and am now going back to it due to a slow db
performance. I have a db for sales leads and have created 3 views based
on the data I need to produce.

However one o the views, which has subqueries to the other views is VERY
slow and it needs to be speeded up, but am unsure how, can anyone
help... below is the sql?

SELECT CGAMain.CGAMainId,CGAMain.Salutation,CGAMain.First Name,

CGAMain.LastName,CGAMain.Salutation2,CGAMain.First Name2,CGAMain.LastName
2,
cgamain.telephone,CGAMain.[Post Code],
other.dbo.users.UserName, other.dbo.agents.[agent_name],
LEADSTATUS.CURRENTSTATUS,leadstatus.activestatus,L eadstatus.[no
answer],CGAMain.rescode,
Agent_displayname As 'Called By'
FROM Leadstatus INNER JOIN CGAMain ON Leadstatus.CGAMainId =
CGAMain.CGAmainId
INNER JOIN other.dbo.users ON Leadstatus.LTAid = other.dbo.users.userref
INNER JOIN other.dbo.agents ON Leadstatus.agentid = other.dbo.agents.id
WHERE
(StatusAssigned = 1)
AND (leadstatus.activestatus = 'Active')

please help???


If you help us to help you, you may get help. Just the query alone is
not much to work from. In general, optimizing queries often requires
access to the database, since there is a lot of information that one
might need to know. But some issues can be easy to spot from a distance.
So, please post the following:

o CREATE TABLE statements for the tables in question.
o All CREATE INDEX statements for the tables. (Incluing PK and UNIQUE
constraints.)
o If any of Leadstatus, users, agents are views, please post the source
for the views.
o Approxamite number of rows per table.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2
Some general advice:
- make sure all tables have a primary key (which automatically means the
key is indexed)
- make sure all foreign keys are indexed
- make sure the foreign keys have exactly the same definition (data type
and size) as the primary key
- you may want to experiment with covering indexes when you access
tables only because of the WHERE clause. In this case, a covering index
on leadstatus(activestatus,CGAMainID) and/or on
leadstatus(CGAMainID,activestatus) might help

HTH,
Gert-Jan
m3ckon wrote:

Hi there,

had to rush some sql and am now going back to it due to a slow db
performance. I have a db for sales leads and have created 3 views based
on the data I need to produce.

However one o the views, which has subqueries to the other views is VERY
slow and it needs to be speeded up, but am unsure how, can anyone
help... below is the sql?

SELECT CGAMain.CGAMainId,CGAMain.Salutation,CGAMain.First Name,

CGAMain.LastName,CGAMain.Salutation2,CGAMain.First Name2,CGAMain.LastName
2,
cgamain.telephone,CGAMain.[Post Code],
other.dbo.users.UserName, other.dbo.agents.[agent_name],
LEADSTATUS.CURRENTSTATUS,leadstatus.activestatus,L eadstatus.[no
answer],CGAMain.rescode,
Agent_displayname As 'Called By'
FROM Leadstatus INNER JOIN CGAMain ON Leadstatus.CGAMainId =
CGAMain.CGAmainId
INNER JOIN other.dbo.users ON Leadstatus.LTAid = other.dbo.users.userref
INNER JOIN other.dbo.agents ON Leadstatus.agentid = other.dbo.agents.id
WHERE
(StatusAssigned = 1)
AND (leadstatus.activestatus = 'Active')

please help???

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 20 '05 #3

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

Similar topics

11
3292
by: Markku Uttula | last post by:
I think I'm doing something wrong. I'm able to connect to Oracle just fine, execute queries and all, but I'm having serious problems with the speed :( For example, the following PHP-script on my...
2
1835
by: Wouter | last post by:
Hi, I was wandering. Does the query speed also depend on the colums that you don't use in the query (so not in the where and not in the select part). I have a lange unused backup field in...
5
2708
by: JENS CONSER | last post by:
Hello NG, We have a performance problem in using a client server solution based on MS SQL-Server 2000 through a VPN tunnel (via broadband internet connection). The SQL Server is running on a...
2
2734
by: jphelan | last post by:
Ever since I successfully applied some techniques for increasing the speed of my 17 meg. Application; it has only made me hunger for more. First, let me list what I have done so far: 1. Split...
27
3207
by: SQL Learner | last post by:
Hi all, I have an Access db with two large tables - 3,100,000 (tblA) and 7,000 (tblB) records. I created a select query using Inner Join by partial matching two fields (X from tblA and Y from...
0
1164
by: hooked888 | last post by:
Hi, I have a database and a query both 100% (with specific index) identical and install and run in my laptop and server but resulting slightly different time frame to complete. Run a query in...
8
6463
by: SaltyBoat | last post by:
Needing to import and parse data from a large PDF file into an Access 2002 table: I start by converted the PDF file to a html file. Then I read this html text file, line by line, into a table...
3
7822
by: victorporton | last post by:
D.K. is traveling from City A to City B. He can stop at some designated spots only. I am trying to use Dijkstra’s algorithm to determine the “spot-to-spot” path that will get D.K. from City A to...
5
2676
by: loveshack | last post by:
Can anyone help me please (i am quite a novice, but having fun learning). Im not sure if this is an ASP problem, a javascript problem or a browser problem. Firstly, everything i have written...
6
1483
by: spider661 | last post by:
im trying to make a perl file that will take all the info from a spell_us.txt file and place it into an sql file i can import into my database but its not working can anyone help please? ...
0
7242
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
7138
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7353
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
7418
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...
1
7075
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...
1
5063
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.