I have report with 1 attribute and 2 metrics.The attribute is Bill rep and the metrics are sum(adjamt) and count(trackingnum).I am using 3 tables
uv_adjustdetails->Sum(adjamt)
uv_payadjust
uv_recorddetails->count(trackingnum)
The sql is pretty simple and i am getting correct result on query analyzer:
select sum(a.fldtotaladjamt) as totalamt,count(distinct(c.fldtrackingnum))as trackingnum,c.fldbillreplastname
from uv_adjustdetails a
join uv_payadjust b
on a.fldrecnum=b.fldrecnum
join uv_recorddetail c
on b.fldtrackingnum=c.fldtrackingnum
group by c.fldbillreplastname
But MSTR generates 3 passes and gives some erroneous result.The MSTR SQL is as follows:
Pass0 - Duration: 0:00:00.23
select a13.fldBillRepUserID fldBillRepUserID,
sum(a11.fldTotalAdjAmt) WJXBFS1
into #ZZT3C010PHLMD000
from uv_AdjustDetails a11
join uv_PayAdjust a12
on (a11.fldRecNum = a12.fldRecNum)
join uv_RecordDetail a13
on (a12.fldTrackingNum = a13.fldTrackingNum)
group by a13.fldBillRepUserID
Pass1 - Duration: 0:00:08.45
select a11.fldBillRepUserID fldBillRepUserID,
count(distinct a11.fldTrackingNum) WJXBFS1
into #ZZT3C010PHLMD001
from uv_RecordDetail a11
group by a11.fldBillRepUserID
Pass2 - Duration: 0:00:03.76
select distinct pa1.fldBillRepUserID fldBillRepUserID,
(a11.fldBillRepLastName + ', ' + a11.fldBillRepFirstName) CustCol,
pa1.WJXBFS1 WJXBFS1,
pa2.WJXBFS1 WJXBFS2
from #ZZT3C010PHLMD000 pa1
join #ZZT3C010PHLMD001 pa2
on (pa1.fldBillRepUserID = pa2.fldBillRepUserID)
join uv_RecordDetail a11
on (pa1.fldBillRepUserID = a11.fldBillRepUserID)
Pass3 - Duration: 0:00:00.09
drop table #ZZT3C010PHLMD000
Pass4 - Duration: 0:00:00.06
drop table #ZZT3C010PHLMD001
Do any one have any idea how this query can be simplified to get correct result set?
Thank you,
uv_adjustdetails->Sum(adjamt)
uv_payadjust
uv_recorddetails->count(trackingnum)
The sql is pretty simple and i am getting correct result on query analyzer:
select sum(a.fldtotaladjamt) as totalamt,count(distinct(c.fldtrackingnum))as trackingnum,c.fldbillreplastname
from uv_adjustdetails a
join uv_payadjust b
on a.fldrecnum=b.fldrecnum
join uv_recorddetail c
on b.fldtrackingnum=c.fldtrackingnum
group by c.fldbillreplastname
But MSTR generates 3 passes and gives some erroneous result.The MSTR SQL is as follows:
Pass0 - Duration: 0:00:00.23
select a13.fldBillRepUserID fldBillRepUserID,
sum(a11.fldTotalAdjAmt) WJXBFS1
into #ZZT3C010PHLMD000
from uv_AdjustDetails a11
join uv_PayAdjust a12
on (a11.fldRecNum = a12.fldRecNum)
join uv_RecordDetail a13
on (a12.fldTrackingNum = a13.fldTrackingNum)
group by a13.fldBillRepUserID
Pass1 - Duration: 0:00:08.45
select a11.fldBillRepUserID fldBillRepUserID,
count(distinct a11.fldTrackingNum) WJXBFS1
into #ZZT3C010PHLMD001
from uv_RecordDetail a11
group by a11.fldBillRepUserID
Pass2 - Duration: 0:00:03.76
select distinct pa1.fldBillRepUserID fldBillRepUserID,
(a11.fldBillRepLastName + ', ' + a11.fldBillRepFirstName) CustCol,
pa1.WJXBFS1 WJXBFS1,
pa2.WJXBFS1 WJXBFS2
from #ZZT3C010PHLMD000 pa1
join #ZZT3C010PHLMD001 pa2
on (pa1.fldBillRepUserID = pa2.fldBillRepUserID)
join uv_RecordDetail a11
on (pa1.fldBillRepUserID = a11.fldBillRepUserID)
Pass3 - Duration: 0:00:00.09
drop table #ZZT3C010PHLMD000
Pass4 - Duration: 0:00:00.06
drop table #ZZT3C010PHLMD001
Do any one have any idea how this query can be simplified to get correct result set?
Thank you,