Optimizing TSQL query
Posted on 2006-06-21
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)
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.