Link to home
Start Free TrialLog in
Avatar of justin11
justin11

asked on

Optimizing TSQL query

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
Avatar of Lowfatspread
Lowfatspread
Flag of United Kingdom of Great Britain and Northern Ireland image

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?
Avatar of imran_fast
imran_fast

create this index it will speed upd the process a bit.
ASKER CERTIFIED SOLUTION
Avatar of imran_fast
imran_fast

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial