Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-05-20 : 09:11:46
|
| John writes "The following stored procedure gets stuck in a continuous loop because the FETCH_STATUS is always zero. If I comment out the second INSERT statement, the cursor runs fine. Is there some restriction or special syntax required when using multiple INSERT statements? I have used multiple UPDATE statements inside a cursor with no problem.CREATE procedure Drew_Temp_SetUpBloomberRatesForOperationasdeclare @BaseRateID intdeclare @RateSourceLID intdeclare @RateAvailabilityFrequencyLID intdeclare @RateUpdateFrequencyLID intdeclare @RateAutoUpdateFlag bitdeclare @RateSymbol varchar(20)declare @RateSeriesInceptionDate smalldatetimedeclare @RateFromCurrencyLID intdeclare @RateCurrencyToLID intdeclare @DayOffset intdeclare @NewRateID intdeclare @ErrorDescription varchar(400)declare bb_rates cursor for select cbr.BaseRateID,RateSourceLID, RateAvailabilityFrequencyLID, RateUpdateFrequencyLID,RateAutoUpdateFlag,RateSymbol,RateSeriesInceptionDate,RateFromCurrencyLID,RateCurrencyToLID,DayOffset from common_baserate cbrinner join common_ratemap crm on cbr.baserateid = crm.baserateid inner join common_rate cr on crm.rateid = cr.rateidopen bb_ratesfetch next from bb_rates into @BaseRateID,@RateSourceLID, @RateAvailabilityFrequencyLID, @RateUpdateFrequencyLID, @RateAutoUpdateFlag, @RateSymbol, @RateSeriesInceptionDate, @RateFromCurrencyLID, @RateCurrencyToLID, @DayOffsetWhile @@fetch_status <> -1 BEGIN Select @RateSourceLID = 1183 --insert into the Common_Rate table INSERT INTO Common_Rate([RateSourceLID], [RateAvailabilityFrequencyLID], [RateUpdateFrequencyLID], [RateAutoUpdateFlag], [RateSymbol], [RateSeriesInceptionDate], [RateFromCurrencyLID], [RateCurrencyToLID], [DayOffset]) VALUES(@RateSourceLID,@RateAvailabilityFrequencyLID,@RateUpdateFrequencyLID,@RateAutoUpdateFlag,@RateSymbol,@RateSeriesInceptionDate,@RateFromCurrencyLID,@RateCurrencyToLID,@DayOffset) Select @NewRateID = max(RateID) from Common_Rate --insert into the Common_RateMap table Insert Into Common_RateMap VALUES (@BaseRateID, @NewRateID) fetch next from bb_rates into @BaseRateID,@RateSourceLID, @RateAvailabilityFrequencyLID, @RateUpdateFrequencyLID, @RateAutoUpdateFlag, @RateSymbol, @RateSeriesInceptionDate, @RateFromCurrencyLID, @RateCurrencyToLID, @DayOffset ENDclose bb_ratesdeallocate bb_ratesGO" |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-05-20 : 12:36:23
|
| Why not just use the SELECT in the cursor declaration in the INSERT with a JOIN? That would be used instead of a cursor.INSERT INTO Common_Rate (([RateSourceLID], [RateAvailabilityFrequencyLID], [RateUpdateFrequencyLID], [RateAutoUpdateFlag], [RateSymbol], [RateSeriesInceptionDate], [RateFromCurrencyLID], [RateCurrencyToLID], [DayOffset])SELECT RateSourceLID, RateAvailabilityFrequencyLID, RateUpdateFrequencyLID, RateAutoUpdateFlag,RateSymbol,RateSeriesInceptionDate,RateFromCurrencyLID,RateCurrencyToLID,DayOffset FROM common_baserate cbrinner join common_ratemap crm on cbr.baserateid = crm.baserateid inner join common_rate cr on crm.rateid = cr.rateidTara |
 |
|
|
kselvia
Aged Yak Warrior
526 Posts |
Posted - 2004-05-20 : 12:57:26
|
| Updateing Common_RateMap (a table joined in the cursor declaration) causes the results returned in the cursor to be inconsistent.Change todeclare bb_rates INSENSITIVE cursor for...or add an ORDER BY to the cursor select statement. (Both methods cause a temporary table to be created which the cursor selects from)(A couple of set based methods may be possible Tara, but John updates Common_Rate and Common_RateMap)Ken |
 |
|
|
|
|
|
|
|