I have the following situation:Timber trucks diliver timber to the mill. Most times along the way they are stopped by the traffic police and are weighed at a weighbridge. Some time later these trucks then arrive at th mill and weighbridge information is then captured again. Trucks can do multiple deliveries per day.The traffic weighbridge info that is captured is: RecID, Date, WeighBridge, VehicleRegistration - (Table: TmpRoad)The mill Weighbridge info is similar: RecID, WBDate, Mill, VehicleRegistration - (Table: weighbridge)Currently I use the following cursor to match the data. (ie: Which police weighbridge record matches a mill delivery)DECLARE tmp CURSOR FOR SELECT RecID, WDateTime, WeighBridge, VehReg FROM TmpRoadOPEN tmpFETCH NEXT FROM tmp into @RecID, @WDT, @WB, @VehRegwhile @@FETCH_STATUS = 0 BEGIN SELECT @tDT = null SELECT @tDT = min(WBDate) from weighbridge where WBDate > @WDt And VehReg = @VehReg SELECT @TMill = null SELECT @TMill = MillID, @MillRecID = RecID from Weighbridge where WBDate = @TDt And VehReg = @VehReg Update TmpRoad Set AriveDate = @TDt, NextMill = @TMill, MillRecID = @MillRecID where RecID = @RecID FETCH NEXT FROM tmp into @RecID, @WDT, @WB, @VehRegEND CLOSE tmpDEALLOCATE tmp
This cursor takes a very long time. Any advice on how to get rid of it and improve performance?ThanksScott