2012-07-03 67 views
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) 

,但它不工作,我看不出有什麼問題

有人能幫助我pleaseeee!

在此先感謝

埃利安娜

+0

如果您發佈的代碼,XML或數據樣本,**請**突出顯示文本編輯器這些線路並在「代碼示例」按鈕,單擊(編輯器工具欄上的{}}可以很好地格式化和語法突出顯示它! –

回答

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 
+0

感謝,現在工作! – Eliana

+0

現在我有以下問題白衣! – Eliana