team2005
asked on
How to speed up this query
Hi!
Have this query:
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 ?
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
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Lurn somthing new today.