0

enter code here私は複雑なレポートを作成しています。そのために、テーブル 1 からいくつかのデータを選択し、テーブル 1 のデータの代わりにテーブル 2、テーブル 3、テーブル 4 からデータを処理する必要があります。

お気に入り

select a,b,c, from table-1

while not rs(table-1).eof

processing data from table-2,
processing data from table-3,
processing data from table-4

行う

私は試しましたが、サブクエリは私の問題を解決できません。カーソルが唯一の選択肢であることはわかっているので、他の解決策があれば教えてください

よろしく。

現時点では、クライアント側でデータを処理し、それをデータベースの一時テーブルに保存してから、そのテーブルからレコードを Crystal レポートにフェッチすることでそれを行っています。ここに私のコードがあります

rs.Open "SELECT distinct Empid,empSalary as EmpSalary,EmpJobStatus From TEmployee where EmpJobStatus ='HIRED' and EmpID not in ( SELECT distinct Empid From VEmpPromotion where convert(VARCHAR(10), PromSalaryMonth , 101)='" & Format(FirstDate, "mm/dd/yyyy") & "') Union SELECT distinct Empid,promempSalary as EmpSalary,PromEmpJobStatus as EmpJobStatus From VEmpPromotion where PromEmpJobStatus ='HIRED' and convert(VARCHAR(10), PromSalaryMonth , 101)='" & Format(FirstDate, "mm/dd/yyyy") & "'", cn, 3, 2


While Not rs.EOF
rsD1.Open "select sum(DATEDIFF(MINUTE,timein,timeout))/60 as HoursWorked ,count(EmpLEave) as EmpLeave,count(TimeIN) as DaysWorked from Tattendance where EmpId =" & rs![EmpId] & " and convert(VARCHAR(10), Attendate, 101)>='" & Format(FirstDate, "mm/dd/yyyy") & "' and convert(VARCHAR(10), attendate, 101)<='" & Format(LastDate, "mm/dd/yyyy") & "'", cn, 3, 2
rsD2.Open "select sum(amount),SUM(CASE EmpTrancID WHEN 1  then amount  ELSE 0 END) AS 'SalaryPaid',SUM(CASE EmpTrancID WHEN 2  then amount  ELSE 0 END) AS 'SalaryAdvancePaid',SUM(CASE EmpTrancID WHEN 3  then amount  ELSE 0 END) AS 'WeeklyIncentivePaid',SUM(CASE EmpTrancID WHEN 4  then amount  ELSE 0 END) AS 'MonthlyIncentivePaid',SUM(CASE EmpTrancID WHEN 5  then amount  ELSE 0 END) AS 'InitialAdvancePaid',SUM(CASE EmpTrancID WHEN 6  then amount  ELSE 0 END) AS 'OtherPayments',SUM(CASE EmpTrancID WHEN 7  then amount  ELSE 0 END) AS 'SalaryAdvanceBack',SUM(CASE EmpTrancID WHEN 8  then amount  ELSE 0 END) AS 'InitialAdvanceBack'From TSalAdvance where TrancStatus =1 and EmpId =" & rs![EmpId] & " and convert(VARCHAR(10), PaidDate, 101)<= '" & Format(DTSearch, "mm/dd/yyyy") & "' and convert(VARCHAR(10), PaidDate, 101)>= '" & Format(FirstDate, "mm/dd/yyyy") & "'", cn, 3, 2
rsD4.Open "select sum(amount),SUM(CASE EmpTrancID WHEN 8  then amount  ELSE 0 END) AS 'TInitialAdvanceBack',SUM(CASE EmpTrancID WHEN 5  then amount  ELSE 0 END) AS 'TInitialAdvancePaid'From TSalAdvance where TrancStatus =1 and EmpId =" & rs![EmpId] & " and convert(VARCHAR(10), SalaryMonth, 101)<'" & Format(LastDate, "mm/dd/yyyy") & "'", cn, 3, 2
rsD5.Open "select sum(amount),SUM(CASE EmpTrancID WHEN 2  then amount  ELSE 0 END) AS 'SalaryAdvancePaid',SUM(CASE EmpTrancID WHEN 7  then amount  ELSE 0 END) AS 'SalaryAdvanceBack'From TSalAdvance where TrancStatus =1 and EmpId =" & rs![EmpId] & " and convert(VARCHAR(10), SalaryMonth, 101)>'" & Format(LastDate, "mm/dd/yyyy") & "'", cn, 3, 2
If IsNull(rsD5![SalaryAdvancePaid]) Then NextAdvPaid = 0 Else NextAdvPaid = rsD5![SalaryAdvancePaid]
If IsNull(rsD5![SalaryAdvanceBack]) Then NextAdvBAck = 0 Else NextAdvBAck = rsD5![SalaryAdvanceBack]
rsD3.Open "select * from SalarySummaryAll", cn, 3, 2
rsD3.AddNew
rsD3![EmpId] = rs![EmpId]
rsD3![EmpSalary] = rs![EmpSalary]
rsD3![EmpJobStatus] = Trim(rs![EmpJobStatus])
.........
.........
rsD3.Update
rs.MoveNext
Wend
4

1 に答える 1

0

あなたのクエリはかなり長いようですが、そこで変数をあまり使用していないようです。

ここで次のように内部および左 (外部) 結合を使用できなかった理由がわかりません。

insert into SalarySummaryAll(EmpId, EmpSalary, ...)
select (TEmployeeAlias.EmpIdAlias, TEmployeeAlias.EmpSalaryAlias, ...) 
from
  (select .... From TEmployee where ...) as TEmployeeAlias
  inner join 
  (select ... From TSalAdvance where ...) as TSalAdvance Alias
     on ...
  inner join  
  (select ... From TSalAdvance where ...) as TSalAdvance Alias
     on ...
  left outer join
  (select...) as tableN 
     on ...

このようなことを試しましたか?もしそうなら、どのような問題に遭遇しましたか?

于 2012-11-30T11:02:27.970 に答える