开发者

SQL Binding error

In SQL Server 2008, the following query works fine:

    WITH T AS (
        SELECT  node.value('fn:local-name(.)', 'varchar(50)') AS Name, node.value('(.)', 'float') AS Value
        FROM    @xml.nodes('data//*') AS x(node)
    )
    SELECT  @OutOfBounds = Count(T.Name)
    FROM    T INNER JOIN [int].RankItems ON [int].RankItems.RankItem = T.Name
    WHERE   (T.Value < [int].RankItems.[Min] OR T.Value > [int].RankItems.[Max])
    OPTION  (OPTIMIZE FOR (@XML UNKNOWN))

However, I wanted to write it as follows:

    WITH T AS (
        SELECT  node.value('fn:local-name(.)', 'varchar(50)') AS Name, node.value('(.)', 'float') AS Value
        FROM    @xml.nodes('data//*') AS x(node)
    )
    SELECT  @OutOfBounds = Count(T.Name)
    FROM    T INNER JOIN [int].RankItems T2 ON T2.RankItem = T.Name
    WHERE   (T.Value < T2.[Min] OR T.Value > T2.[Max])
    OPTION  (OPTIMIZE FOR (@XML UNKNOWN开发者_如何学C))

This gives me a "could not bind" error on T2. I can't see why.


You're missing the AS statement, ie

FROM    T INNER JOIN [int].RankItems AS T2 ON T2.RankItem = T.Name
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜