尝试在LEFT JOINS表之前使用where子句时出现错误

时间:2018-08-09 21:15:45

标签: sql

我的代码:

Failed to find configured root that contains <path>

1 个答案:

答案 0 :(得分:1)

由于语法错误,您会收到错误消息。 where子句过滤记录,因此通常在查询末尾使用它,例如

 SELECT 
    rs.[Id]         AS 'Id'
    ,bkngSrc.[SourceName]    AS 'BkngSrc'
    ,payMode.[Description]   AS 'PayMode'
    ,rs.[GuestName]          AS 'GuestName'
    ,rs.[Addr]               AS 'Addr'
    ,rs.[City]               AS 'City'
    ,rs.[EntryDate]          AS 'EntryDate'
FROM dbo.ResvReg rs
LEFT JOIN [dbo].[BkngSource] bkngSrc on rs.[BkngSrc] = bkngSrc.[Id]
LEFT JOIN [dbo].[PaymentMode] payMode on rs.[PayMode] = payMode.[Id]
WHERE EntryDate>= '11/08/2018'

如果要先过滤然后再加入,请使用编写嵌套查询。这样的事情可以解决问题

SELECT 
        t.[Id]         AS 'Id'
        ,bkngSrc.[SourceName]    AS 'BkngSrc'
        ,payMode.[Description]   AS 'PayMode'
        ,t.[GuestName]          AS 'GuestName'
        ,t.[Addr]               AS 'Addr'
        ,t.[City]               AS 'City'
        ,t.[EntryDate]          AS 'EntryDate'
from
(
    SELECT *
    FROM dbo.ResvReg rs
    WHERE EntryDate>= '11/08/2018'
) t
LEFT JOIN [dbo].[BkngSource] bkngSrc on t.[BkngSrc] = bkngSrc.[Id]
LEFT JOIN [dbo].[PaymentMode] payMode on t.[PayMode] = payMode.[Id]