Q&A

  • SQL문의 결과가 틀립니다.
With Qry1 Do

Begin

Close;

Sql.Clear;

Sql.Add(' SELECT SUM(NVL(DR_AMT,0)) SLIP_DR1, ' );

Sql.Add(' SUM(NVL(CR_AMT,0)) SLIP_CR1 ' );

Sql.Add(' FROM ACCT11V2 ' );

Sql.Add(' WHERE WORK_ID = ''' + Trim(dWork_Id.Text) + ''' ' );

Sql.Add(' AND SLIP_DATE BETWEEN ''' + Trim(eSlip_FR.Text) + ''' ' );

Sql.Add(' AND ''' + Trim(eSlip_TO.Text) + ''' ' );

Sql.Add(' AND SLIP_DIV = ''2'' ' );

Open;



End;

With Qry2 Do

Begin

Close;

Sql.Clear;

Sql.Add(' SELECT SUM(NVL(DR_AMT,0)) SLIP_DR2, ' );

Sql.Add(' SUM(NVL(CR_AMT,0)) SLIP_CR2 ' );

Sql.Add(' FROM ACCT11V2 ' );

Sql.Add(' WHERE WORK_ID = ''' + Trim(dWork_Id.Text) + ''' ' );

Sql.Add(' AND SLIP_DATE BETWEEN ''' + Trim(eSlip_FR.Text) + ''' ' );

Sql.Add(' AND ''' + Trim(eSlip_TO.Text) + ''' ' );

Sql.Add(' AND SLIP_DIV = ''1'' ' );

Open;



End;



With MQuery Do

Begin



DisableControls;



Close;

Sql.Clear;

Sql.Add(M_Sql);

Sql.Add(' WHERE WORK_ID = ''' + Trim(dWork_Id.Text) + ''' ' );

Sql.Add(' AND SLIP_DATE BETWEEN ''' + Trim(eSlip_FR.Text) + ''' ' );

Sql.Add(' AND ''' + Trim(eSlip_TO.Text) + ''' ' );

Sql.Add(' GROUP BY ACCT_CODE, ACCT_NAME ' );



Open;



Label_Count.Caption := Format('Record Count : %d 건 ', [RecordCount]);

EnableControls;

End;

With SumQry Do

Begin

Close;

Sql.Clear;

Sql.Add(' SELECT SUM(NVL(A.DR_AMT ,0)) CR_SUM, ' );

Sql.Add(' SUM(NVL(A.CR_AMT ,0)) CR_SUM, ' );

Sql.Add(' SUM(NVL(B.DR_AMT ,0)) SLIP_DR1, ' );

Sql.Add(' SUM(NVL(B.CR_AMT ,0)) SLIP_CR1, ' );

Sql.Add(' SUM(NVL(C.DR_AMT ,0)) SLIP_DR2, ' );

Sql.Add(' SUM(NVL(C.CR_AMT ,0)) SLIP_CR2, ' );

Sql.Add(' SUM(NVL(A.DR_AMT ,0)) + SUM(NVL(C.DR_AMT ,0)) + SUM(NVL(C.CR_AMT ,0)) TOT_DR, ');

Sql.Add(' SUM(NVL(A.CR_AMT ,0)) + SUM(NVL(B.DR_AMT ,0)) + SUM(NVL(B.CR_AMT ,0)) TOT_CR ');

Sql.Add(' FROM ACCT11V2 A,ACCT11V2 B,ACCT11V2 C ' );

Sql.Add(' WHERE A.WORK_ID = ''' + Trim(dWork_Id.Text) + ''' ' );

Sql.Add(' AND A.SLIP_DATE BETWEEN ''' + Trim(eSlip_FR.Text) + ''' ' );

Sql.Add(' AND ''' + Trim(eSlip_TO.Text) + ''' ' );

Sql.Add(' AND B.SLIP_DIV = ''2'' ' );

Sql.Add(' AND C.SLIP_DIV = ''1'' ' );



Open;



End;

같은 TABLE 을 사용하여 QUERY문 3개를 만들었습니다.

그 세개의 QUERY문을 이용하여 SUMQRY문에서 합을 구하려고 하는데요 계속 합의 값이 이상하게 나와요,.... 고수님들 제발 도와주세요...

1  COMMENTS
  • Profile
    이영도 2001.03.04 01:03
    주야 wrote:

    > With Qry1 Do

    > Begin

    > Close;

    > Sql.Clear;

    > Sql.Add(' SELECT SUM(NVL(DR_AMT,0)) SLIP_DR1, ' );

    > Sql.Add(' SUM(NVL(CR_AMT,0)) SLIP_CR1 ' );

    > Sql.Add(' FROM ACCT11V2 ' );

    > Sql.Add(' WHERE WORK_ID = ''' + Trim(dWork_Id.Text) + ''' ' );

    > Sql.Add(' AND SLIP_DATE BETWEEN ''' + Trim(eSlip_FR.Text) + ''' ' );

    > Sql.Add(' AND ''' + Trim(eSlip_TO.Text) + ''' ' );

    > Sql.Add(' AND SLIP_DIV = ''2'' ' );

    > Open;

    >

    > End;

    > With Qry2 Do

    > Begin

    > Close;

    > Sql.Clear;

    > Sql.Add(' SELECT SUM(NVL(DR_AMT,0)) SLIP_DR2, ' );

    > Sql.Add(' SUM(NVL(CR_AMT,0)) SLIP_CR2 ' );

    > Sql.Add(' FROM ACCT11V2 ' );

    > Sql.Add(' WHERE WORK_ID = ''' + Trim(dWork_Id.Text) + ''' ' );

    > Sql.Add(' AND SLIP_DATE BETWEEN ''' + Trim(eSlip_FR.Text) + ''' ' );

    > Sql.Add(' AND ''' + Trim(eSlip_TO.Text) + ''' ' );

    > Sql.Add(' AND SLIP_DIV = ''1'' ' );

    > Open;

    >

    > End;

    >

    > With MQuery Do

    > Begin

    >

    > DisableControls;

    >

    > Close;

    > Sql.Clear;

    > Sql.Add(M_Sql);

    > Sql.Add(' WHERE WORK_ID = ''' + Trim(dWork_Id.Text) + ''' ' );

    > Sql.Add(' AND SLIP_DATE BETWEEN ''' + Trim(eSlip_FR.Text) + ''' ' );

    > Sql.Add(' AND ''' + Trim(eSlip_TO.Text) + ''' ' );

    > Sql.Add(' GROUP BY ACCT_CODE, ACCT_NAME ' );

    >

    > Open;

    >

    > Label_Count.Caption := Format('Record Count : %d 건 ', [RecordCount]);

    > EnableControls;

    > End;

    > With SumQry Do

    > Begin

    > Close;

    > Sql.Clear;

    > Sql.Add(' SELECT SUM(NVL(A.DR_AMT ,0)) CR_SUM, ' );

    > Sql.Add(' SUM(NVL(A.CR_AMT ,0)) CR_SUM, ' );

    > Sql.Add(' SUM(NVL(B.DR_AMT ,0)) SLIP_DR1, ' );

    > Sql.Add(' SUM(NVL(B.CR_AMT ,0)) SLIP_CR1, ' );

    > Sql.Add(' SUM(NVL(C.DR_AMT ,0)) SLIP_DR2, ' );

    > Sql.Add(' SUM(NVL(C.CR_AMT ,0)) SLIP_CR2, ' );

    > Sql.Add(' SUM(NVL(A.DR_AMT ,0)) + SUM(NVL(C.DR_AMT ,0)) + SUM(NVL(C.CR_AMT ,0)) TOT_DR, ');

    > Sql.Add(' SUM(NVL(A.CR_AMT ,0)) + SUM(NVL(B.DR_AMT ,0)) + SUM(NVL(B.CR_AMT ,0)) TOT_CR ');

    > Sql.Add(' FROM ACCT11V2 A,ACCT11V2 B,ACCT11V2 C ' );

    > Sql.Add(' WHERE A.WORK_ID = ''' + Trim(dWork_Id.Text) + ''' ' );

    > Sql.Add(' AND A.SLIP_DATE BETWEEN ''' + Trim(eSlip_FR.Text) + ''' ' );

    > Sql.Add(' AND ''' + Trim(eSlip_TO.Text) + ''' ' );

    > Sql.Add(' AND B.SLIP_DIV = ''2'' ' );

    > Sql.Add(' AND C.SLIP_DIV = ''1'' ' );

    >

    > Open;

    >

    > End;

    > 같은 TABLE 을 사용하여 QUERY문 3개를 만들었습니다.

    > 그 세개의 QUERY문을 이용하여 SUMQRY문에서 합을 구하려고 하는데요 계속 합의 값이 이상하게 나와요,.... 고수님들 제발 도와주세요...



    잘이해는안되는데요..

    걍 CalcuField를 쓰면 잘나올꺼 같은디...