?
Solved

Optimizing TSQL query

Posted on 2006-06-21
5
Medium Priority
?
413 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

752 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