0

我有一个可以插入或更新到另一个表的触发器。

在我添加更新之前,触发器是有效的,在我添加更新之后,有一个错误

当不使用 EXISTS 引入子查询时,选择列表中只能指定一个表达式。

你能帮我解决这个问题吗?

UPDATE 
    OLT_Balance_Update
SET 
    StartOfDayBalance = 
       (SELECT dbo.OLT_Cash_Posting.ClientNo, 
               ROUND(dbo.OLT_ArAp.NetArAp, 0) + ISNULL(dbo.OLT_Cash_Posting.Amount, 0) + ISNULL(dbo.interface_rlf_deposits.PortoQuantity * dbo.interface_rlf_deposits.PortoAverage, 0) + ISNULL(dbo.OLT_ArAp.InvestorBAC, 0) AS StartOfDayBalance
        FROM  dbo.OLT_Cash_Posting 
        LEFT OUTER JOIN dbo.OLT_Client ON dbo.OLT_Cash_Posting.ClientNo = dbo.OLT_Client.ClientNo 
        LEFT OUTER JOIN dbo.OLT_ArAp ON dbo.OLT_Cash_Posting.clientno = dbo.OLT_ArAp.ClAcNo 
        LEFT OUTER JOIN dbo.interface_rlf_deposits ON dbo.OLT_Client.ClientNo = dbo.interface_rlf_deposits.clAcno)
        WHERE 
              Clientno IN (SELECT P.ClientNo 
                           FROM  OLT_Balance_Update P, inserted I  
                           WHERE P.ClientNo = I.ClientNo)
4

1 回答 1

0

尝试这个:

根据您的 SET StartOfDayBalance 语句返回多个值

UPDATE OLT_Balance_Update
SET StartOfDayBalance =  ROUND(dbo.OLT_ArAp.NetArAp, 0) + ISNULL(dbo.OLT_Cash_Posting.Amount, 0) + ISNULL(dbo.interface_rlf_deposits.PortoQuantity * dbo.interface_rlf_deposits.PortoAverage, 0) + ISNULL(dbo.OLT_ArAp.InvestorBAC, 0)
FROM  dbo.OLT_Cash_Posting 
LEFT OUTER JOIN dbo.OLT_Client 
    ON dbo.OLT_Cash_Posting.ClientNo = dbo.OLT_Client.ClientNo 
LEFT OUTER JOIN dbo.OLT_ArAp 
    ON dbo.OLT_Cash_Posting.clientno = dbo.OLT_ArAp.ClAcNo 
LEFT OUTER JOIN dbo.interface_rlf_deposits 
    ON dbo.OLT_Client.ClientNo = dbo.interface_rlf_deposits.clAcno
WHERE Clientno IN 
(SELECT P.ClientNo FROM  OLT_Balance_Update P join inserted I on P.ClientNo = I.ClientNo)
于 2012-08-06T06:33:46.653 回答