델파이 5.0에 SQL2000server를 사용하여 프로그램을 짜 보았지만
" invalid use keyword. Token : select Line Number 7"이라는 에러가 발생하네요. 똑같은 문장으로 SQL Explore에서 돌려보면 원하는 결과치를 얻을 수 있습니다. .
서브쿼리를 사용하면 속도가 늦어 진다는데 보통 몇개까지 사용할 수 있는지요. (혹시 서브쿼리를 8개나 사용해서 그런건 아닌지....)
(프로그램 내용)
with Query1.SQL do
begin
Clear;
Add('select si_code, si_name, ');
Add('IsNull(T11.Busu,0)+IsNull(T21.Busu,0)+IsNull(T31.Busu,0), ');
Add('IsNull(T11.Kum,0)+IsNull(T21.Kum,0)+IsNull(T31.Kum,0), ');
Add('IsNull(T12.Busu,0)+IsNull(T22.Busu,0)+IsNull(T32.Busu,0), ');
Add('IsNull(T12.Kum,0)+IsNull(T22.Kum,0)+IsNull(T32.Kum,0), ');
Add('T4.Kum, T5.Kum From '+SName+', ');
Add('(select osi_scode Code, sum(osi_su) Busu, su(osi_net) Kum From '+OName1);
Add(' where osi_eyy+osi_emm+osi_edd <= '+Buf_Day+' and ');
Add('osi_scode >= ''8900'' and osi_scode <= ''8999'' and osi_sec2 = ''1''');
Add(' group by osi_scode) T11, ');
Add('(select osi_scode Code, sum(osi_su) Busu, sum(osi_net) Kum From '+OName1);
Add(' where osi_eyy+osi_emm+osi_edd <= '+Buf_Day+' and ');
Add('osi_scode >= ''8900'' and osi_scode <= ''8999'' and osi_sec2 = ''2''');
Add(' group by osi_scode) T12, ');
Add('(select osi_scode Code, sum(osi_su) Busu, sum(osi_net) Kum From '+OName2);
Add(' where osi_eyy+osi_emm+osi_edd <= '+Buf_Day+' and ');
Add('osi_scode >= ''8900'' and osi_scode <= ''8999'' and osi_sec2 = ''1''');
Add(' group by osi_scode) T21, ');
Add('(select osi_scode Code, sum(osi_su) Busu, sum(osi_net) Kum From '+OName2);
Add(' where osi_eyy+osi_emm+osi_edd <= '+Buf_Day+' and ');
Add('osi_scode >= ''8900'' and osi_scode <= ''8999'' and osi_sec2 = ''2''');
Add(' group by osi_scode) T22, ');
Add('(select osi_scode Code, sum(osi_su) Busu, sum(osi_net) Kum From '+OName3);
Add(' where osi_eyy+osi_emm+osi_edd <= '+Buf_Day+' and ');
Add('osi_scode >= ''8900'' and osi_scode <= ''8999'' and osi_sec2 = ''1''');
Add(' group by osi_scode) T31, ');
Add('(select osi_scode Code, sum(osi_su) Busu, sum(osi_net) Kum From '+OName3);
Add(' where osi_eyy+osi_emm+osi_edd <= '+Buf_Day+' and ');
Add('osi_scode >= ''8900'' and osi_scode <= ''8999'' and osi_sec2 = ''2''');
Add(' group by osi_scode) T32, ');
Add('(select substring(cms_code,4,4) Code, sum(Cms_kum) Kum From '+IName);
Add(' where cms_day < '+Buf_Day+' and ');
Add('substring(cms_code,4,4) >= ''8900'' and substring(cms_code,4,4) <= ''8999''');
Add(' group by substring(cms_code,4,4)) T4, ');
Add('(select substring(cms_code,4,4) Code, sum(Cms_kum) Kum From '+IName);
Add(' where cms_day = '+Buf_Day+' and ');
Add('substring(cms_code,4,4) >= ''8900'' and substring(cms_code,4,4) <= ''8999''');
Add(' group by substring(cms_code,4,4)) T5 ');
Add(' where si_code = T11.Code and si_code = T12.Code and si_code = T21.Code');
Add(' and si_code = T22.Code and si_code = T31.Code and si_code = T32.Code');
Add(' and si_code = T4.Code and si_code = T5.Code');
end;
Query1.Open;
" invalid use keyword. Token : select Line Number 7"
지금 난 오류는 SQL구문 오류인듯한데요..
7번째 줄에 보면
이렇게 되어있는데..
sum을 잘못입력하신거 같네요..^^