-1
Msg 156, Level 15, State 1, Line 107
Incorrect syntax near the keyword 'on'.

我有一个相当大的查询,我将只提供其中的一小部分。我收到以下语法错误ON SplitAddresses.Client_id=d_client.CLIENT_ID

...
left join
(SELECT  distinct
   T.MLIS_CLIENT_ADDRESS_1,T.Client_id,
   Left(T.MLIS_CLIENT_ADDRESS_1, IsNull(SplitAddresses.Pos - 1, 2147483647)) Address1,
   Substring(T.MLIS_CLIENT_ADDRESS_1, SplitAddresses.Pos + 1, 2147483647) Address2
FROM

      d_client
    T 
   OUTER APPLY (
      SELECT TOP 1 NullIf(PatIndex(Delimiter, T.MLIS_CLIENT_ADDRESS_1), 0) Pos
      FROM (
         VALUES ('% Suite %'), ('% Ste %'), ('% Bldg %'), ('% Building %'), ('%#%')
      ) SplitAddresses (Delimiter)
      WHERE T.MLIS_CLIENT_ADDRESS_1 LIKE SplitAddresses.Delimiter 
      ORDER BY Pos
   ) SplitAddresses
on 
SplitAddresses.Client_id=d_client.CLIENT_ID


WHERE...

我是在语法上做了一些明显错误还是有更深层次的问题?非常感谢你的帮助。

4

3 回答 3

4

这是您的 SQL 的重新格式化,可能会使您的问题更加清楚:

left join
(
SELECT Distinct
    T.MLIS_CLIENT_ADDRESS_1,
    T.Client_id,
    Left(T.MLIS_CLIENT_ADDRESS_1, IsNull(SplitAddresses.Pos - 1, 2147483647)) Address1,
    Substring(T.MLIS_CLIENT_ADDRESS_1, SplitAddresses.Pos + 1, 2147483647) Address2
FROM
    d_client T 
        OUTER APPLY 
        (
            SELECT TOP 1 
                NullIf(PatIndex(Delimiter, T.MLIS_CLIENT_ADDRESS_1), 0) Pos
            FROM 
            (
                VALUES 
                    ('% Suite %'), 
                    ('% Ste %'), 
                    ('% Bldg %'), 
                    ('% Building %'), 
                    ('%#%')
            ) SplitAddresses (Delimiter)
            WHERE 
                T.MLIS_CLIENT_ADDRESS_1 LIKE SplitAddresses.Delimiter 
            ORDER BY Pos
        ) SplitAddresses
on SplitAddresses.Client_id=d_client.CLIENT_ID

看起来你在 SplitAddresses 之前错过了第二个 ) :

left join
    (
    SELECT Distinct
        T.MLIS_CLIENT_ADDRESS_1,
        T.Client_id,
        Left(T.MLIS_CLIENT_ADDRESS_1, IsNull(SplitAddresses.Pos - 1, 2147483647)) Address1,
        Substring(T.MLIS_CLIENT_ADDRESS_1, SplitAddresses.Pos + 1, 2147483647) Address2
    FROM
        d_client T 
            OUTER APPLY 
            (
                SELECT TOP 1 
                    NullIf(PatIndex(Delimiter, T.MLIS_CLIENT_ADDRESS_1), 0) Pos
                FROM 
                (
                    VALUES 
                        ('% Suite %'), 
                        ('% Ste %'), 
                        ('% Bldg %'), 
                        ('% Building %'), 
                        ('%#%')
                ) SplitAddresses (Delimiter)
                WHERE 
                    T.MLIS_CLIENT_ADDRESS_1 LIKE SplitAddresses.Delimiter 
                ORDER BY Pos
            ) SA
    ) SplitAddresses
    on SplitAddresses.Client_id=d_client.CLIENT_ID
于 2012-07-25T21:49:11.023 回答
1

看起来您在声明中给出d_client了别名T而不是使用它on

于 2012-07-25T21:41:56.367 回答
1

结束前的括号on结束outer apply,而不是select您要使用的。添加另一个结束括号。

于 2012-07-25T21:43:43.610 回答