Link to home
Create AccountLog in
Avatar of team2005
team2005

asked on

How to speed up this query

Hi!

Have this query:

Declare
@SQL varchar(2000),
@version_id varchar(50),
@MyCursor CURSOR,
@perioden varchar(4),
@moneden varchar(2),
@FORECASTYEARWEEK int,
@DATAAREAID varchar(4),
@itemid varchar(20),
@ITEMIDDAT varchar(24)


SET @MyCursor = CURSOR FAST_FORWARD
FOR
Select DATAAREAID,ITEMID,version_id,FORECASTYEARWEEK,ITEMIDDAT From dbo.TMP_Forcast_Hit_Ratio_Art_version

OPEN @MyCursor
FETCH NEXT FROM @MyCursor
INTO @DATAAREAID,@itemid,@Version_id,@FORECASTYEARWEEK,@ITEMIDDAT
                                           
WHILE @@FETCH_STATUS = 0              
BEGIN
    
    -- Insert record in dimension table
    INSERT Into FACT_Forcast_Hit_Ratio
    (    
    [FORECASTGROUPID], 
    [DATAAREAID],
    [ITEMID],
    [version_id],
    [FORECASTYEARWEEK],
    [ITEMIDDAT]  
    )
    SELECT 
      FORC.ABC_FORECASTGROUPID+FORC.DATAAREAID,
      FORC.DATAAREAID,
      @itemid,
      @version_id,
      @FORECASTYEARWEEK,
      @itemid+@DATAAREAID
    FROM dbo.TMP_ABC_FORCAST as FORC
      
    FETCH NEXT FROM @MyCursor
    INTO @DATAAREAID,@itemid,@Version_id,@FORECASTYEARWEEK,@ITEMIDDAT
END

Open in new window



My problem is this query thaks a loooong time..

It will return about 28 million records when complete.. (takes hours)

How can i speed this up ?
ASKER CERTIFIED SOLUTION
Avatar of deviprasadg
deviprasadg
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of team2005
team2005

ASKER

Thanks alot :)

Lurn somthing new today.