0

我正在尝试“内部连接”两个表值参数,但是当我执行查询时它永远需要并且我必须停止在 ms sql server management studio 2008 中进行调试。

查询:

    @allClients [dbo].[ImportedClients] READONLY,
    @NewClients [dbo].[ImportedClients] READONLY

--Update Clients table in db with new clients

    UPDATE [dbo].[Clients]
        SET 

            Email = ISNULL(ct.Email, x.Email), 
            FirstName = ISNULL(ct.FirstName, x.FirstName), 
            LastName = ISNULL(ct.LastName, x.LastName), 
            Telephone = ISNULL(ct.Telephone, x.Telephone), 
            Cellphone = ISNULL(ct.Cellphone, x.Cellphone), 



        FROM @NewClients ct
        inner join @allClients x 
        ON (x.Email = ct.Email)     

        WHERE ct.Status > -1 

我要做的是:更新@NewClients 和@allClients 中存在的行的所有客户端信息,因此我使用了内部联接。是否可以加入两个表值参数?即使有几行,此查询也不起作用(查询不会在没有错误的情况下完成)。

有什么建议么?

4

1 回答 1

1

您需要[dbo].[Clients]在 SQL 的FROM子句中引用。

像这样的东西:

@allClients [dbo].[ImportedClients] READONLY,
@NewClients [dbo].[ImportedClients] READONLY

--Update Clients table in db with new clients

UPDATE [dbo].[Clients]
SET 
    Email = ISNULL(ct.Email, x.Email), 
    FirstName = ISNULL(ct.FirstName, x.FirstName), 
    LastName = ISNULL(ct.LastName, x.LastName), 
    Telephone = ISNULL(ct.Telephone, x.Telephone), 
    Cellphone = ISNULL(ct.Cellphone, x.Cellphone), 

FROM [dbo].[Clients] c
    INNER JOIN @NewClients ct ON (c.Email = ct.Email)     
    INNER JOIN @allClients x  ON (x.Email = ct.Email)     
WHERE ct.Status > -1 
于 2012-11-06T15:00:57.653 回答