Copy SQL From Access To Delphi Script
I found a difficult with SQL on Delphi, I use ADOconnection and ADOQuery.
Here these Query
With ADOQuery Do
Begin
SQL.Text:='SELECT QUnionSAPiutang.kd_Customer, T_Customer.nama_customer, '
+'CDbl(IIf(IsNull(DSum("SA","QSumSAPiutang","kd_Customer='" & [QUnionSAPiutang].[kd_Customer] & "' AND ' +'Tgl<#1/1/2010# ")),0,DSum("SA","QSumSAPiutang","kd_Customer='" & [QUnionSAPiutang].[kd_Customer] & "' ' +'AND Tgl<#1/1/2010# "开发者_开发百科))) AS SA1, Sum(QUnionSAPiutang.D) AS Debit, Sum(QUnionSAPiutang.K) AS Kredit, ' +'[SA1]+[Debit]-[Kredit] AS SAkh '
+'FROM QUnionSAPiutang INNER JOIN T_Customer ON '
+'QUnionSAPiutang.kd_Customer = T_Customer.kd_customer '
+'WHERE (((QUnionSAPiutang.Tgl) Between #1/1/2010# And #1/31/2010#)) '
+'GROUP BY QUnionSAPiutang.kd_Customer, T_Customer.nama_customer';
End
That Query Above has an error.... I try to fix, but still have an error. I hope you can help my problem, please fix that Query. I use Ms.Access XP for Database, if I run that Query on Accsess, the error is nothing.
I use three object T_Customer, QUnionSAPiutang, and QSumSAPiutang.
Where the red text is a part of QSumSAPiutang. coz QSumSAPiutang not directly Join with the others, it is call with DSum.
Please help me, Thank you for your time. I hope reply from you soon....
It seems that you are trying to make a select join between TQuery components. That's not possible AFAIK.
You need a TQuery component against you DB referencing DB tables (no other TQuery's)
SQL.Text="select myDBtable1.field1, myDBtable2.fieldx from myDBTable1 inner join myDBtable2 ..."
DSUM is not SQL. It is an extended stored procedure provided by MSACCESS. In an Access application it actually references the CurrentDB object.
If you don't run that query in Access, there is no Access Application.CurrentDB object, and no DSUM extended stored procedure.
Created another stored query in the database that uses an aggregate query to do the sum, then join to that, instead of using DSUM.
It is possible to use an Access object to run your queries, instead of using an ADO object. But that is normally even more difficult, slower, and flakier, than using another aggregate query.
精彩评论