2011-03-01 37 views
0
USE [ASPDryrun] 
GO 

    UPDATE [dbo].[Users] 
    SET [ID] = [IU].[PersNo], 
     [CostCenter] = [CC].[CostCenterID], 
     [OrgUnit] = [OU].[OrgUnitID] 
    FROM [dbo].[Users], 
     [dbo].[Import_UserData] AS [IU], 
     [dbo].[CostCenters] AS [CC], 
     [dbo].[OrgUnits] AS [OU] 
    WHERE [CC].[ID] = [IU].[CostCtr] 
    AND [OU].[ID] = [IU].[OrgUnit] 
    AND [IU].[CorporateEmail] IN (SELECT [Email] 
            FROM [dbo].[Users]) 

GO 

我想更新某些用戶在另一張表上的電子郵件時的信息。但是這個查詢更新所有用戶並且不知道什麼是錯誤的,你能幫助我嗎?謝謝當電子郵件在另一個表上時如何更新表格?

+4

您沒有加入任何有關的'dbo.Users'表查詢中的其他表的條件。 – 2011-03-01 16:47:09

+0

也許我應該加上這個條件:'AND [IU]。[CorporateEmail] = [dbo]。[Users]。[Email]' Email是唯一的比較字段 – Vicent 2011-03-01 16:52:46

回答

0

最後,我可以只另一個條件更解決問題。下面是結果:

USE [ASPDryrun] 
GO 
     UPDATE [dbo].[Users] 
     SET [ID] = [IU].[PersNo], 
      [CostCenter] = [CC].[CostCenterID], 
      [OrgUnit] = [OU].[OrgUnitID] 
     FROM [dbo].[Import_UserData] AS [IU], 
      [dbo].[CostCenters] AS [CC], 
      [dbo].[OrgUnits] AS [OU], 
      [dbo].[Users] AS [U] 
     WHERE [CC].[EricssonID] = [IU].[CostCtr] 
      AND [OU].[EricssonID] = [IU].[OrgUnit] 
      AND [IU].[CorporateEmail] = [U].[Email] 
     GO 
0

顯式連接會更好嗎?只是猜測,不知道什麼樣的數據實際上是這些... 像

相關問題