代码之家  ›  专栏  ›  技术社区  ›  Juan Tarquino

即使我正在使用“内部联接”,也会收到“无联接谓词”警告。

  •  1
  • Juan Tarquino  · 技术社区  · 14 年前

    我使用的是SQL Server 2008 R2,我有一个内部联接3个表的查询:

    select * from  t1 INNER JOIN t2 on t1."Account Key" = t2."Account Key"
    INNER JOIN t3 on t2."Account Key" = t3."Account Key"
    

    问题是我在第二个内部联接上得到了一个“无联接谓词”警告;此外,它还执行了第一个联接与t3生成的表的叉积,这使得查询永远运行(除了给出错误的结果)。

    我运行了以下查询,以查看在最后一次联接的两侧是否有相等的帐户键:

    select "Account Key" from  t1 INNER JOIN t2 on t1."Account Key" = t2."Account Key"
    INTERSECT 
    select "Account Key" from t3 on t2."Account Key" = t3."Account Key"
    

    我得到0行,这意味着在联接的两侧没有相等的帐户键。然而, 因为我使用的是“内部联接”,所以原始查询不应该给出0行而不是一个叉积吗?

    更新 :t3是一个视图,其[帐户密钥]列实际上是一个计算列:

    CAST(bid AS varchar(5)) + '-' + dbo.ConvertNumericToPaddedChar(RMKEY, 20) AS [Account Key]
    

    更新 :dbo.convertNumericTopAddedChar(rmkey,20)是导致问题的原因。似乎在进行内部联接时,SQL Server不能使用使用用户定义函数生成的列。

    你们中有人知道怎么解决这个问题吗?

    1 回复  |  直到 13 年前
        1
  •  1
  •   Greg    14 年前

    我不知道你的例子为什么行不通。尝试用[方括号]而不是“引号”来括住列名。

    select * from  t1
    INNER JOIN t2 on t1.[Account Key] = t2.[Account Key]
    INNER JOIN t3 on t2.[Account Key] = t3.[Account Key]