Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Long running stored procedure

$
0
0

Hi

I'm fairly new to this so please be patient.

I have the following stored procedure that takes best part of 10 hours to run!!!

Table Motor.MTMIEARN has 16012916 records

Table Motor.MTMIMTRF has 376358 records

Table lookup.AGENT has 2000 records

Is there anything obvious that would spped this up

Many Thanks

USE

[SolvencyIIdwh]


GO



/****** Object:  StoredProcedure [GENERIC].[usp_MIEARNData]    Script Date: 08/02/2013 11:02:01 ******/


SET

ANSI_NULLSON

GO

SET

QUOTED_IDENTIFIERON

GO


/*********************************************************************************************************/

/***  Create output PRIVATE CAR - MIEARN                                                                 */

                                                                                                  


/***                                                                                                     */

/***  Date Author Reason                                                                       */

/***  20130408 MR New                                                                          */

/***                                                                                                     */

/*********************************************************************************************************/



CREATE

PROCEDURE [GENERIC].[usp_MIEARNData]


AS

INSERT

INTO SolvencyIIdwh.MOTOR.MIEARNData(

IncMonth

,[Cover]

   

,[Stnd]

   

,[EarnedPrem]

   

,[EarnedPol])



 

/**************MIEARN/MIMTRF output file*************/

 

SELECT

SUBSTRING(Cast(e.MEACPDASVARCHAR(11)),3,2)+SUBSTRING(Cast(e.MEACPDASVARCHAR(11)),6,2)AS'Month'    

,CASE t.MMCOVR

WHEN'01'THEN'C'


ELSE'N'


END AS'Cover' 

,t.MMSTNDAS'Standard'


,SUM(e.TOTEARNPRM)AS'Earned Premium'


,SUM(CASEWHEN dotcode='23536P'THEN(TOTEARNPOL* .40)

ELSE TOTEARNPOLEND)AS'Earned Policies'


 

FROM SolvencyIIdwh.MOTOR.MTMIMTRF t

 

JOIN SolvencyIIdwh.MOTOR.MTMIEARN e

 

ON t.MMPOLN= e.MEPOLN

 

AND t.MMAPSQ= e.MEAPSQ

 

AND t.MMAPDT= e.MEAPDT

 

JOIN SolvencyIIdwh.LOOKUP.Agent a

 

ON t.MMAGNT= a.AgentNo

 

WHERE t.MMSCDT>='01 Jan 1993'


 

GROUPBY e.MEACPD,t.MMCOVR,t.MMSTND



GO


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>