2

我正在尝试更新表列并像这样设置另一个列的值

UPDATE dbo.TempTable t2
SET    Introd = t1.Introd, AgtCode = t1.[Agt Code], PIN = t1.PIN, IDNo = t1.[ID No] 
FROM   dbo.CustomerData t1
WHERE  t2.PolicyNo = t1.Policy
AND    t2.Prod = t1.Prod
AND    t2.Introd IS DISTINCT FROM t1.Introd

但它对我不起作用,

4

3 回答 3

1

您似乎对 SQL 使用了更多的 Postgres 格式。这是 SQL Server 等效项:

UPDATE t2
    SET    Introd = t1.Introd,
           AgtCode = t1.[Agt Code],
           PIN = t1.PIN,
           IDNo = t1.[ID No] 
    FROM   dbo.TempTable t2 join
           dbo.CustomerData t1
           on t2.PolicyNo = t1.Policy and
              t2.Prod = t1.Prod and
              (t2.Introd <> t1.Introd or
               t2.Introd is NULL and t1.Introd is not NULL or
               t2.Introd is not NULL and t1.Introd is NULL
              )
于 2013-08-31T12:43:44.853 回答
1
UPDATE
    Table_1
SET
    Table_1.FieldToBeUpdated = T2.FieldFromWhichToBeUpdated
FROM
    Table_1 T1
INNER JOIN
    Table_2 T2
ON 
    T1.ConditionFieldFromTable1 = T2.ConditionFieldFromTable2

或者

UPDATE
    Table_1 T1,Table_2 T2
SET
    T1.FieldToBeUpdated = T2.FieldFromWhichToBeUpdated
WHERE
    SI.AnyField = RAN.AnyOtherField
于 2013-08-31T12:33:09.287 回答
0

第一种方法:

    UPDATE dbo.TempTable t2
    SET    t2.Introd = t1.Introd, t2.AgtCode = t1.[Agt Code], 
           t2.PIN = t1.PIN, t2.IDNo = t1.[ID No] 
    FROM t2
    LEFT JOIN dbo.CustomerData t1
    ON t2.PolicyNo = t1.Policy
    AND t2.Prod = t1.Prod
    AND t2.Introd IS DISTINCT FROM t1.Introd

第二种方法:

UPDATE dbo.TempTable t2
SET    t2.Introd = t1.Introd, t2.AgtCode = t1.[Agt Code], 
t2.PIN = t1.PIN, t2.IDNo = t1.[ID No]
FROM t2, dbo.CustomerData t1
where t2.PolicyNo = t1.Policy
AND t2.Prod = t1.Prod
AND t2.Introd IS DISTINCT FROM t1.Introd
于 2013-08-31T12:40:03.930 回答