Solved

Optimizing TSQL query

Posted on 2006-06-21
5
395 Views
Last Modified: 2012-05-05
Hello,
I am running a query which takes about one hour.Can any one help me optimize it.
Here is the query:

Select * into #TAD  from
OPENQUERY(DWDB, 'select DW_PR_SVC_LOAN_ID,DELQ_PRIN_AMT
as Total_Amt_Due from DW_PR_SVC_LOAN_MOD ')

Update  tbl_MaestroCampaignList set TotalAmountDue = #TAD.Total_Amt_Due
from (tbl_MaestroCampaignList inner join #TAD
on tbl_MaestroCampaignList.DW_PR_SVC_LOAN_ID = #TAD.DW_PR_SVC_LOAN_ID)
where
datediff(day,GetDate(),campaignDate)=0 and CampaignName ='FirstLienPreFCL'

I have to basically calculate Total Amount only for the loans in tbl_MaestroCampaignList .But I have to get these values from Datawarehouse table which has about a million loans. How to optimize it.
Thanks  bunch
0
Comment
Question by:justin11
  • 2
5 Comments
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 16951532
what takes the time
the select into
or the update ?

which version of sql server?

why isn't the maestrocampaignlist in the warehouse?

why do you need to  datediff on campaigndate?
0
 
LVL 28

Expert Comment

by:imran_fast
ID: 16952152
create this index it will speed upd the process a bit.
0
 
LVL 28

Accepted Solution

by:
imran_fast earned 500 total points
ID: 16952160
create this index it will speed up the process a bit.

create nonclustered index ix_tbl_MaestroCampaignList_01 on tbl_MaestroCampaignList(CampaignName,DW_PR_SVC_LOAN_ID)
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now