我的脚本返回两个值,其中只需要一个值。我想将执行Sel_NPCA_Min_PlanID_ByID的结果分配给合并参数的最后一部分。这可行吗?
ALTER PROCEDURE [dbo].[Sel_NPCA_PlanID]
(@ID int)
AS
BEGIN
DECLARE @PlanID int
EXEC @PlanID = Sel_NPCA_Min_PlanID_ByID @ID
SELECT
COALESCE(checkboxTicked.PLAN_ID, firstPlanDiscussedAgreed.PLAN_ID, firstPlanAgreed.PLAN_ID, @PlanID) AS PLAN_ID
FROM referral
LEFT JOIN checkboxTicked
ON referral.ID = checkboxTicked.ID
LEFT JOIN firstPlanDiscussedAgreed
ON referral.ID = firstPlanDiscussedAgreed.ID AND checkboxTicked.PLAN_ID IS NULL
LEFT JOIN firstPlanAgreed
ON referral.ID = firstPlanAgreed.ID AND checkboxTicked.PLAN_ID IS NULL AND firstPlanDiscussedAgreed.PLAN_ID IS NULL
WHERE referral.ID = @ID
END
如果要
将过程的输出分配给变量,则可能应该使用(标量)函数而不是过程。另一种选择是在过程参数列表中使用输出变量。