아래 쿼리문을 쿼리분석기에 돌리면 잘 돌아갑니다.
쿼리 분석기에 돌린 쿼리문도 아래쪽에 올렸습니다.
그런데 델파이에서 돌리면 '0' 구문이 잘못되었다고 나오네요
답변 부탁해요 .. ㅠㅠ
SQL.Clear;
SQL.BeginUpdate;
SQL.Add('SELECT right(BTB.ipxx_addr, 3) as drawIP, BTB.macx_addr, C.code_name AS info_name, info_code, rslt_valu, rslt_valu_now, ');
SQL.Add(' B.comp_name,B.work_grup,BTB.updt_date ');
SQL.Add(' FROM (SELECT ipxx_addr, macx_addr,info_code, MAX(rslt_valu) AS rslt_valu, MAX(rslt_valu_now) AS rslt_valu_now, max(updt_date) AS updt_date ');
SQL.Add(' FROM (SELECT ipxx_addr, macx_addr,info_code, rslt_valu, '' AS rslt_valu_now, updt_date ');
SQL.Add(' FROM SY_SYTM_INFO ');
SQL.Add(' WHERE info_gubn = ' + QuotedStr('0'));
SQL.Add(' UNION ALL ');
SQL.Add(' SELECT ipxx_addr, macx_addr,info_code, '' AS rslt_valu, rslt_valu, updt_date ');
SQL.Add(' FROM SY_SYTM_INFO ');
SQL.Add(' WHERE info_gubn = ' + QuotedStr('1'));
SQL.Add(' ) AS ATB ');
SQL.Add(' GROUP BY ipxx_addr, macx_addr,info_code ');
SQL.Add(' ) AS BTB LEFT OUTER JOIN IP_COLL_INFO B ON B.macx_addr = BTB.macx_addr ');
SQL.Add(' LEFT OUTER JOIN CD_COMN_CODE C ON C.majr_code = ' + QuotedStr('SYTMINFO'));
SQL.Add(' AND C.minr_code = BTB.info_code ');;
SQL.Add(' WHERE rslt_valu <> rslt_valu_now ');;
SQL.EndUpdate;
Open;
-- 쿼리분석기 --
SELECT right(BTB.ipxx_addr, 3) as drawIP, BTB.macx_addr, C.code_name AS info_name, info_code, rslt_valu, rslt_valu_now,
B.comp_name,B.work_grup,BTB.updt_date
FROM (SELECT ipxx_addr, macx_addr,info_code, MAX(rslt_valu) AS rslt_valu, MAX(rslt_valu_now) AS rslt_valu_now, max(updt_date) AS updt_date
FROM (SELECT ipxx_addr, macx_addr,info_code, rslt_valu, '' AS rslt_valu_now, updt_date
FROM SY_SYTM_INFO
WHERE info_gubn = '0'
UNION ALL
SELECT ipxx_addr, macx_addr,info_code, '' AS rslt_valu, rslt_valu, updt_date
FROM SY_SYTM_INFO
WHERE info_gubn = '1'
) AS ATB
GROUP BY ipxx_addr, macx_addr,info_code
) AS BTB LEFT OUTER JOIN IP_COLL_INFO B ON B.macx_addr = BTB.macx_addr
LEFT OUTER JOIN CD_COMN_CODE C ON C.majr_code = 'SYTMINFO'
AND C.minr_code = BTB.info_code
WHERE rslt_valu <> rslt_valu_now
(') 싱글 따옴표는 ('') 두개를 찍어야 합니다..
'' as alias 라고 하실때는 '''' as alias로 사용하셔야 합니다.
그래도 문제가 발생한다면...
memo1.text := sql.text;
sql.savetofile('c:\sql.sql');
하셔서 open하기 직전의 쿼리 문장을 받아서 쿼리 분석기에서 테스트해보세요..
그럼..