Help Refactoring SQL Query

30 pts.
Tags:
Refactoring
SQL
SQL Query
Dear Friend Below is my SQL Query
select DISTINCT Auditdata.ID,ns.ProviderMaster_ID as CDRComment 
            from Auditdata AuditData 
            inner join AuditMaster am     on    am.ID=AuditData.AuditMaster_ID 
            inner join HomeCircleMaster hcm     on   hcm.Ori_CircleMaster_ID=am.CircleMaster_ID      
 and hcm.Ori_ServiceTypeMaster_ID=1     and hcm.Dest_ServiceTypeMaster_ID=1 
           inner join NoSeriesMaster ns     on (ns.CircleMaster_ID=am.CircleMaster_ID     or  ns.CircleMaster_ID=hcm.Dest_CircleMaster_ID)     and ns.ProviderMaster_ID<>am.ProviderMaster_ID      and ns.ServiceTypeMaster_ID=1 
         INNER JOIN    NoSeriesMaster_Prefix PD     ON SUBSTRING(AuditData.CallTo, 1, CONVERT(INT, PD.PrefixLen)) = PD.PrefixNo          
AND LEN(AuditData.CallTo) = CONVERT(VARCHAR(10), CONVERT(INT, PD.PrefixLen) + CONVERT(INT, PD.AfterPrefixLen))      AND PD.PrefixNo + ns.NoSeries = LEFT (AuditData.CallTo, len(ns.NoSeries) + CONVERT(INT, PD.PrefixLen))   
where  AuditData.TATCallType is null       and  AuditData.AuditMaster_ID=74     and PrefixType='CALL'

from the above Query  below part of query takes lot of time to run

   inner join NoSeriesMaster ns     on (ns.CircleMaster_ID=am.CircleMaster_ID     or     ns.CircleMaster_ID=hcm.Dest_CircleMaster_ID)     
and ns.ProviderMaster_ID<>am.ProviderMaster_ID      and ns.ServiceTypeMaster_ID=1 
      INNER JOIN    NoSeriesMaster_Prefix PD    ON AuditData.CallTo like PD.PrefixNo + '%'          
ANDAuditData.CallTolen =  PD.PrefixLen +  PD.AfterPrefixLen      AND PD.PrefixNo + ns.NoSeries = LEFT (AuditData.CallTo, ns.NoSerieslen + PD.PrefixLen)   
where  AuditData.TATCallType is null       and  AuditData.AuditMaster_ID=74     and PrefixType='CALL'


 How can modify above Query to fast

Every columns used in the inner join and where clause defined .index..

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Denny Cherry
    Can you show the Execution plan for the query. You probably need to make adjustments to your indexes.
    66,130 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following