0

我在尝试在临时表中插入记录时遇到问题

我有一个临时表#TmpCapacityTable

CapacityDate    InstallerCode   WorkAreadID FoxtelCodeID    value
2/8/12      BAW     7       1510        3
2/8/12      BAW     7       1508        3

第二个临时表#TmpAdjustmentTable

CapacityDate    InstallerCode   WorkAreadID fFoxtelCodeID   value
2/8/12      BAW     7       1510        1
2/8/12      BAW     7       1508        1
2/8/12      BAW     7       1509        1

我需要插入#TmpCapacityTable那些不在但有的行中#TmpAdjustmentTable,在示例中只有代码 1509

我正在使用

Insert into #TmpCapacityTable
select * from #TmpAdjustmentTable 
    where #TmpAdjustmentTable.CapacityDate not in (select #TmpCapacityTable.CapacityDate from #TmpCapacityTable)  
    and   #TmpAdjustmentTable.WorkAreadID not in (select #TmpCapacityTable.WorkAreadID from #TmpCapacityTable)
    and   #TmpAdjustmentTable.InstallerCode not in (select #TmpCapacityTable.InstallerCode from #TmpCapacityTable)
    and   #TmpAdjustmentTable.FoxtelCodeID not in (select #TmpCapacityTable.FoxtelCodeID from #TmpCapacityTable)

但它不起作用,我看不出问题出在哪里

有人可以帮我拜托!!!

提前致谢

埃利亚纳

4

1 回答 1

0
INSERT INTO TmpCapacityTable(CapacityDate, InstallerCode, WorkAreaID, FoxtelCodeID, value)
    SELECT  ta.CapacityDate, ta.InstallerCode, ta.WorkAreaID, ta.FoxtelCodeID, ta.value
      FROM  #TmpAdjustmentTable ta
            LEFT OUTER JOIN #TmpCapacityTable tc
                ON  ta.CapacityDate     = tc.CapacityDate
                AND ta.InstallerCode    = tc.InstallerCode
                AND ta.FoxtelCodeID     = tc.FoxtelCodeID 
     WHERE  tc.value IS NULL
于 2012-07-04T00:00:54.943 回答