我在这个查询中遇到错误。第一个内部查询在我们独立运行时正确执行。但是当我在完整查询中包含相同内容时,它会提示错误。
UPDATE GL_BudgetPlanDetails bpd
SET (CommittedAmt07) = (
SELECT SUM (case
when fa.amtacctdr > 0 then (fa.amtacctdr*-1)
when fa.amtacctcr > 0 then fa.amtacctcr else 0 end )
FROM fact_acct fa
WHERE fa.datetrx between '2014-09-01' and '2014-09-30'
AND fa.isactive ='Y'
AND fa.account_ID =758
AND fa.AD_Client_ID =11
AND fa.AD_Org_ID =50001)
WHERE (
(
SELECT gbp.c_year_id
FROM GL_BudgetPlan gbp
WHERE gbp.GL_BudgetPlan_ID = bpd.GL_BudgetPlan_ID
AND gbp.isactive ='Y'
) = '2014'
)
AND bpd.account_ID =758
答案 0 :(得分:2)
删除CommittedAmt07的括号
UPDATE GL_BudgetPlanDetails bpd SET Period01Amt =(SELECT SUM(fa.amtacctdr> 0时的情况,然后fa.amtacctcr> 0时的情况(fa.amtacctdr * -1)) 然后fa.amtacctcr else 0 end)FROM fact_acct fa WHERE fa.datetrx介于'2014-09-01'和'2014-09-30'之间并且fa.isactive ='Y'和fa.account_ID = 758 AND fa.AD_Client_ID = 11 AND fa.AD_Org_ID = 50001)WHERE((SELECT gbp.c_year_id FROM GL_BudgetPlan gbp WHERE gbp.GL_BudgetPlan_ID = bpd.GL_BudgetPlan_ID AND gbp.isactive ='Y')='2014')AND bpd.account_ID = 758
答案 1 :(得分:0)
我认为问题是()arround CommittedAmt07
,因此您的查询应该看起来像
UPDATE GL_BudgetPlanDetails bpd
SET CommittedAmt07 = (
SELECT SUM (case
when fa.amtacctdr > 0 then (fa.amtacctdr*-1)
when fa.amtacctcr > 0 then fa.amtacctcr else 0 end )
FROM fact_acct fa
WHERE fa.datetrx between '2014-09-01' and '2014-09-30'
AND fa.isactive ='Y'
AND fa.account_ID =758
AND fa.AD_Client_ID =11
AND fa.AD_Org_ID =50001)
WHERE (
(
SELECT gbp.c_year_id
FROM GL_BudgetPlan gbp
WHERE gbp.GL_BudgetPlan_ID = bpd.GL_BudgetPlan_ID
AND gbp.isactive ='Y'
) = '2014'
)
AND bpd.account_ID =758;
如果您查看here,可以看到如果您只更新一列,则不需要括号。但是你需要使用它们用某种数组更新它们。请参阅文档
中的此示例UPDATE weather SET (temp_lo, temp_hi, prcp) = (temp_lo+1, temp_lo+15, DEFAULT)
WHERE city = 'San Francisco' AND date = '2003-07-03';
同样对于9.3,他们声明从SELECT语句填充它还没有被发现(在链接页面的最低点)