I have a stored procedure where I call a different stored procedure that creates a temp table and then use that temp table in a while exists loop. When I go to use the field names in the while loop, I am getting an error that one of the fields from the temp table doesn't exist when it does.
Below is the code:
call GetProc1 (0, 1, 5, 111);
while exists
(
select GlobalMarketDesc, MarketFamilyName, Country, rank from tmpRanks;
)
do
begin
If GlobalMarketDesc = 'United States' then
set strEventType = concat(GlobalMarketDesc, ' - ', MarketFamilyName);
Else
set strEventType = concat(GlobalMarketDesc, ' - ', Country, ' - ', MarketFamilyName);
end if;
end;
end while;
The error Error Code: 1054 Unknown column 'GlobalMarketDesc' in 'field list'
When I changed to a cursor, I still get the above error. Here is my new code using a cursor:
DECLARE no_more_records INT;
DECLARE cur_EventRanks CURSOR FOR
select * from tmpEventRanks;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_records=1;
set no_more_records = 0;
open cur_EventRanks;
cur_Loop: while (no_more_records=0)
do
begin
-- Set up the Event Type field
If GlobalMarketDesc = 'United States' then
set strEventType = concat(GlobalMarketDesc, ' - ', MarketFamilyName);
Else
set strEventType = concat(GlobalMarketDesc, ' - ', Country, ' - ', MarketFamilyName);
end if;
end while cur_Loop;
close cur_EventRanks;