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
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 に答える
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 に答える
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

2番目の方法:

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 に答える