2014-02-26 2 views
0

I라는 마스터 테이블에 여러 테이블을 조인을 시도하고있다 '주장'(아래 코드) 세 개의 테이블이 다음과 같은 조건MS 액세스와 SQL의 배수 가입 및 WHERE 절을

  1. [뉴욕 주 메디 케이드 비용 일정 Jan12] 키가 중복되어 있고 조회 테이블의 두 날짜 사이에 마스터 테이블의 값이있는 올바른 레코드를 선택해야합니다.
  2. [NYS Medicaid Fee Schedule Apr13]에 중복 키가 있으며 마스터 테이블의 값이 정확한 레코드를 선택해야합니다 조회 테이블의 두 날짜 사이에 있음
  3. [NY Medicare]가 중복되었습니다. 올바른 레코드를 선택하려면 'Zone'을 두 번째 레벨로 봐야합니다.

WHERE 절을 하나만 사용하면 쿼리가 작동하고 아무런 문제가 없습니다. 개별 테이블에 대해 하나 또는 두 개의 추가 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] 

답변

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]