我试图将多个表连接到名为“Claims”的主表(下面的代码) 三个表具有以下条件
当我只使用一个WHERE子句时,查询有效并且没有问题。为单独的表添加1或两个额外的WHERE条件会导致麻烦。
我在互联网上研究了很多,发现括号对ACCESS很重要。我看到了关于多个连接的正确语法的示例,但没有关于特定表的WHERE子句的多个连接。
我希望我只是误解了如何放置括号。
FROM ( ( ( ( ( ( [Claims]
LEFT JOIN [BillType] ON [Claims].[Bill_Type] = [BillType].[BillType_Bill Type Key] )
LEFT JOIN [PlaceofService] ON [Claims].[Place_of_Service] = [PlaceofService].[POS_Place of Service] )
LEFT JOIN [Participating] ON [Claims].[TIN] = [Participating].[TIN] )
LEFT JOIN [NYS Medicaid Fee Schedule Apr11] ON [Claims].[FivedigitProcCode] = [NYS Medicaid Fee Schedule Apr11].[Apr11_NYS_CODE] )
LEFT JOIN [NYS Medicaid Fee Schedule Jan12] ON [Claims].[FivedigitProcCode] = [NYS Medicaid Fee Schedule Jan12].[Jan12_NYS_CODE]
WHERE [Claims].[BeginningDOS] BETWEEN [NYS Medicaid Fee Schedule Jan12].[Jan12_NYS_EFFECTIVE DATE] AND [NYS Medicaid Fee Schedule Jan12].[Jan12_NYS_END DATE] )
LEFT JOIN [NYS Medicaid Fee Schedule Apr13] ON [Claims].[FivedigitProcCode] = [NYS Medicaid Fee Schedule Apr13].[Apr13_NYS_CODE]
WHERE [Claims].[BeginningDOS] BETWEEN [NYS Medicaid Fee Schedule Apr13].[Apr13_NYS_EFFECTIVE DATE] AND [NYS Medicaid Fee Schedule Apr13].[Apr13_NYS_END DATE] )
LEFT JOIN [NY Medicare] ON [Claims].[FivedigitProcCode] = [NY Medicare].[MEDICARE_HCPCS CODE]
WHERE [Claims].[Zone] = [NY Medicare].[MEDICARE_ZONE]
答案 0 :(得分:1)
SQL查询只有一个where
子句。您应该将这些条件更改为on
条件的一部分:
FROM ( ( ( ( ( ( [Claims]
LEFT JOIN [BillType] ON [Claims].[Bill_Type] = [BillType].[BillType_Bill Type Key] )
LEFT JOIN [PlaceofService] ON [Claims].[Place_of_Service] = [PlaceofService].[POS_Place of Service] )
LEFT JOIN [Participating] ON [Claims].[TIN] = [Participating].[TIN] )
LEFT JOIN [NYS Medicaid Fee Schedule Apr11] ON [Claims].[FivedigitProcCode] = [NYS Medicaid Fee Schedule Apr11].[Apr11_NYS_CODE] )
LEFT JOIN [NYS Medicaid Fee Schedule Jan12] ON [Claims].[FivedigitProcCode] = [NYS Medicaid Fee Schedule Jan12].[Jan12_NYS_CODE]
AND [Claims].[BeginningDOS] BETWEEN [NYS Medicaid Fee Schedule Jan12].[Jan12_NYS_EFFECTIVE DATE] AND [NYS Medicaid Fee Schedule Jan12].[Jan12_NYS_END DATE] )
LEFT JOIN [NYS Medicaid Fee Schedule Apr13] ON [Claims].[FivedigitProcCode] = [NYS Medicaid Fee Schedule Apr13].[Apr13_NYS_CODE]
AND [Claims].[BeginningDOS] BETWEEN [NYS Medicaid Fee Schedule Apr13].[Apr13_NYS_EFFECTIVE DATE] AND [NYS Medicaid Fee Schedule Apr13].[Apr13_NYS_END DATE] )
LEFT JOIN [NY Medicare] ON [Claims].[FivedigitProcCode] = [NY Medicare].[MEDICARE_HCPCS CODE]
AND [Claims].[Zone] = [NY Medicare].[MEDICARE_ZONE]