内部连接两个表值的参数不起作用

时间:2012-11-06 14:21:42

标签: sql sql-server sql-server-2008

我正在尝试“内连接”两个表值参数,但是当我执行查询时,它需要永远,我必须在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中存在的行的所有客户端信息,以便我使用内连接。 是否可以加入两个表值参数? 即使有几行,这个查询也没有(查询没有完成而没有错误)。

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

您需要在SQL的[dbo].[Clients]子句中引用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