현재 사용하는건 mssql2000 인데요..
여기서 해당 일자의 데이터를 구할려고합니다..
쿼리문은
SELECT A.DLCO_CD, C.DLCO_NM , A.DPT_CD ,
CASE CON.CONTRACT_CD WHEN 'V' THEN CON.CONTRACT_MONEY ELSE 0 END AS CONTRACT_MONEY,
DATEADD(MONTH, DATEDIFF(MONTH, 0, A.SEL_DT ), 0 ) AS rmonth ,
SUM(case when b.xwh_slf in ('20002', '20013') then -1 * (b.rl_sel_amt + b.rl_vat) else (b.rl_sel_amt + b.rl_vat) end) as saleSum
FROM TBL_SEL_SLIP AS A
INNER JOIN TBL_SEL_DTLS AS B
ON A.SEL_DT = B.SEL_DT
AND A.SEL_NO = B.SEL_NO
LEFT JOIN TBL_DLCO_INFO AS C
ON A.DLCO_CD = C.DLCO_CD
LEFT JOIN TBL_GDS_INFO AS GDS
ON B.GDS_CD = GDS.GDS_CD
LEFT OUTER JOIN TBL_MAK_INFO AS MAK
ON GDS.MAK_CD = MAK.MAK_CD
LEFT OUTER JOIN TBL_MAK_GDS_N1 AS MAKN1
ON GDS.MAK_CD = MAKN1.MAK_CD
AND GDS.GDS_CL_N1 = MAKN1.GDS_CL_N1
INNER JOIN TBL_DLCO_CONTRACT AS CON
ON A.DLCO_CD = CON.DLCO_CD
WHERE 1=1
AND A.SEL_DT BETWEEN '20120701' AND '20120831'
AND (A.DLCO_CD = '' OR '' = '')
AND (A.DPT_CD = '' OR '' = '')
AND A.DEL_YN = 'N'
AND C.AGENCY_KIND LIKE '%V%'
AND CON.CONTRACT_CD = 'V'
AND GDS.MAK_CD IN ('75','73')
OR (GDS.MAK_CD = '3' AND GDS.GDS_CL_N1 = '185')
OR (GDS.MAK_CD = '9' AND GDS.GDS_CL_N1 = '169')
OR (GDS.MAK_CD = '6' AND GDS.GDS_CL_N1 = '4')
OR (GDS.MAK_CD = '70' AND GDS.GDS_CL_N1 = '178')
GROUP BY A.DLCO_CD, C.DLCO_NM, A.DPT_CD, CON.CONTRACT_MONEY, CON.CONTRACT_CD ,
DATEADD(MONTH,DATEDIFF(MONTH,0,A.SEL_DT),0)
이렇게 사용중인데요.. 제가 조인을 잘못한건지 조건을 잘못 준건지..
A.SEL_DT BETWEEN '20120701' AND '20120831' <=== 일자의 데이터만 가져오고 싶은데.. 전체 데이터가 나옵니다.
AND GDS.MAK_CD IN ('75','73')
OR (GDS.MAK_CD = '3' AND GDS.GDS_CL_N1 = '185')
OR (GDS.MAK_CD = '9' AND GDS.GDS_CL_N1 = '169')
OR (GDS.MAK_CD = '6' AND GDS.GDS_CL_N1 = '4')
이부분이 추가 되면요.. 이 부분을 빼면.. 원하는 데이터만 나오고요..
수정을 어떻게 해야 하나요.??
감사합니다..
|