我有以下存储过程:
CREATE DEFINER=`sleuser`@`%` PROCEDURE `PCDD`(
in ProjectID int,
in MonthName varchar(50),
in ServiceCode varchar(50),
in ProjectName varchar(50)
)
BEGIN
SET @PCProjID = ProjectID;
SET @PCSN1 = "020." + ServiceCode + ".000";
SET @Month = MonthName;
SET @ImpCostID = ProjectName;
SET @ImpCostTask1 = "020." + ServiceCode + ".000";
SELECT
project.project_id,
'FP' as Phase,
ImportCost.OriginalCommitments,
ImportCost.ApprovedCommitmentChanges,
sum(RegisteredChangeOrders) + sum(OriginalContractPrice) as CurrentAssigned,
sum(ProjectCostBudget.PendingChangeOrders) as PendingScopeChanges,
FROM `RCLY-DEV`.ProjectCostBudget
inner join project on project.project_id =
ProjectCostBudget.ProjectID
inner join ImportCost on ImportCost.ProjectID = project.pmis
where ImportCost.ProjectID = @ImpCostID and
ImportCost.Task = @PCSN1 and
ProjectCostBudget.ProjectID = @PCProjID and
ProjectCostBudget.ServiceNumber = @ImpCostTask1
我称之为:
call PCDD(2,'September%2018','0000','RLCY-BB-01')
其中“ 0000”需要从“ 0000”到“ 6000”变化。当我为“ 0000”运行SP时,它返回预期的结果,但是当我将其更改为其他值时,它仅返回所有null。我尝试将@ PCSN1和@ ImpCostTask1更新为:
SET @PCSN1 = ("020.", ServiceCode, ".000");
SET @ImpCostTask1 = ("020.", ServiceCode, ".000");
但是我得到了错误
“操作数应包含1列。
我在这里做错了什么?为什么对一个ServiceCode无效,而对其他ServiceCode无效?
答案 0 :(得分:2)
您需要使用'
enqoute字符串文字和CONCAT
而不是'+'来进行字符串连接:
SET @PCSN1 = "020." + ServiceCode + ".000";
=>
SET @PCSN1 = CONCAT('020.', ServiceCode, '.000');
相同于:
SET @ImpCostTask1 = "020." + ServiceCode + ".000";
=>
SET @ImpCostTask1 = CONCAT('020.', ServiceCode, '.000');