1
請檢查下面錯誤代碼:1137不能重新打開表:「amountforagents」
DELIMITER $$
CREATE DEFINER=`ntc`@`%` PROCEDURE `new_procedure`(in v_Agentid int)
BEGIN
select (select @DayAmount :=sum(AmountRecevied) as Totoalamountperday from
collection_master
where AgentID=v_Agentid and day(Date_Time)= day(CURRENT_DATE())),
(select @MonthAmount:=sum(AmountRecevied) as Totoalamountperday from
collection_master
where AgentID=v_Agentid and date_time between DATE_FORMAT(NOW() ,'%Y-%m-01') and LAST_DAY(now() - interval 0 month)),
(select @YearAmount:= sum(AmountRecevied) as Totoalamountpermonth from
collection_master
where AgentID=v_Agentid and year(Date_Time) =YEAR(CURRENT_DATE())),
(select @Position := @Position + 1 AS Rank from
collection_master ,(SELECT @Position := 0) r
where AgentID=v_Agentid
group by AgentID
) as position;
DROP TEMPORARY TABLE IF EXISTS amountforagents;
create TEMPORARY table amountforagents (agentId int,DayAmount decimal,MonthAmount decimal,YearAmount decimal,Position int,totalamountreceived decimal);
set @agentId =v_Agentid;
update amountforagents SET totalamountreceived = (select ifnull(DayAmount,0)+ifnull(MonthAmount,0)+ifnull(YearAmount,0) from amountforagents where agentId=v_Agentid);
INSERT Into amountforagents
(agentId,DayAmount,MonthAmount,YearAmount,Position,totalamountreceived) values(@agentId,
@DayAmount,@MonthAmount,@YearAmount,@Position,@totalamountreceived);
select agentId,DayAmount,MonthAmount,YearAmount,Position,totalamountreceived from amountforagents;
END
在這裏,我triing給我的順序通過SP爲totalamountreceived基於三列的總量在分配排名sp,這三列在temp表中,但它顯示錯誤錯誤代碼:1137無法重新打開表格:'amountforagents'
不,我已經嘗試用SET @totalamountreceived我出空 – stpdevi
您可以編輯您原來的職位,以顯示當你習慣了'set @ totalamountreceived'你嘗試過什麼碼?我在上面發佈的示例應該可以正常工作。 –
與上面相同只是我刪除了更新amountforagents SET totalamountreceived =(選擇ifnull(DayAmount,0)+ ifnull(MonthAmount,0)+ ifnull(YearAmount,0)from amountforagents where agentId = v_Agentid);並添加了SET @totalamountreceived = ifnull(@DayAmount,0) + ifnull(@MonthAmount,0) + ifnull(@YearAmount,0); – stpdevi