select
cd.cdr_reporttype,m.mhb_code,sum(cast(round((cd.cdr_Postage*dbo.fn_CurrencyUnit('CUR0005')),3) as decimal(15,3))) as postage,
sum(cast(round((cd.cdr_HandlingCost*dbo.fn_CurrencyUnit('CUR0005')),3) as decimal(15,3))) as HandlingCost,
sum(cast(round((cd.cdr_TranshipmentLH*dbo.fn_CurrencyUnit('CUR0005')),3)as decimal(15,3))) as Tanat_LH,
sum(cast(round((cd.cdr_Postage*dbo.fn_CurrencyUnit('CUR0005')),3) as decimal(15,3)))+
sum(cast(round((cd.cdr_HandlingCost*dbo.fn_CurrencyUnit('CUR0005')),3) as decimal(15,3)))+
sum(cast(round((cd.cdr_TranshipmentLH*dbo.fn_CurrencyUnit('CUR0005')),3)as decimal(15,3))) as TotalCosts
from
mos_IEL i with(nolock),mos_DisposalCode d with(nolock),mos_MailHub m with(nolock),mos_MailHub mo with(nolock),
mos_cdreport cd with(nolock),mos_servicetype s with(nolock)
where
cd.cdr_id=isnull(null,cd.cdr_id) and
i.IEL_IELNumber=cd.cdr_IELNumber and
cd.cdr_disposalid=d.dis_id and m.mhb_id=cd.cdr_remailcentreid and
mo.mhb_id=cd.cdr_origincentreid and
s.ser_id=cd.cdr_servicetypeid and
d.dis_discontinued=i.IEL_Discontinued and m.mhb_discontinued=i.IEL_Discontinued and
cd.cdr_discontinued=i.IEL_Discontinued and i.IEL_Discontinued=0 and
--cd.cdr_reporttype='C' and
cd.cdr_remailcentreid= isnull(null, cd.cdr_remailcentreid )and
cd.cdr_remailcentreid in (select mhb_id from mos_MailHub with(nolock) where mhb_discontinued=0 and mhb_countryid=isnull(null,mhb_countryid))and
cd.cdr_origincentreid=isnull(null, cd.cdr_origincentreid )and
cd.cdr_origincentreid in (select mhb_id from mos_MailHub with(nolock) where mhb_discontinued=0 and mhb_countryid=isnull(null,mhb_countryid)) and
convert(varchar(12),cd.cdr_reportingfrom,101)>= convert(varchar(12),convert(datetime,'1/1/2009'),101) and
convert(varchar(12),cd.cdr_reportingto,101)<=convert(varchar(12),convert(datetime,'12/31/2009'),101)
group by cd.cdr_reporttype,m.mhb_code having cdr_reporttype='C'
union
select
cd.cdr_reporttype, mo.mhb_code,sum(cast(round((cd.cdr_Postage*dbo.fn_CurrencyUnit('CUR0005')),3) as decimal(15,3))) as postage,
sum(cast(round((cd.cdr_HandlingCost*dbo.fn_CurrencyUnit('CUR0005')),3) as decimal(15,3))) as HandlingCost,
sum(cast(round((cd.cdr_TranshipmentLH*dbo.fn_CurrencyUnit('CUR0005')),3)as decimal(15,3))) as Tanat_LH,
sum(cast(round((cd.cdr_Postage*dbo.fn_CurrencyUnit('CUR0005')),3) as decimal(15,3)))+
sum(cast(round((cd.cdr_HandlingCost*dbo.fn_CurrencyUnit('CUR0005')),3) as decimal(15,3)))+
sum(cast(round((cd.cdr_TranshipmentLH*dbo.fn_CurrencyUnit('CUR0005')),3)as decimal(15,3))) as TotalCosts
from
mos_IEL i with(nolock),mos_DisposalCode d with(nolock),mos_MailHub m with(nolock),mos_MailHub mo with(nolock),
mos_cdreport cd with(nolock),mos_servicetype s with(nolock)
where
cd.cdr_id=isnull(null,cd.cdr_id) and
i.IEL_IELNumber=cd.cdr_IELNumber and
cd.cdr_disposalid=d.dis_id and m.mhb_id=cd.cdr_remailcentreid and
mo.mhb_id=cd.cdr_origincentreid and
s.ser_id=cd.cdr_servicetypeid and
d.dis_discontinued=i.IEL_Discontinued and m.mhb_discontinued=i.IEL_Discontinued and
cd.cdr_discontinued=i.IEL_Discontinued and i.IEL_Discontinued=0 and
cd.cdr_remailcentreid= isnull(null, cd.cdr_remailcentreid )and
cd.cdr_remailcentreid in (select mhb_id from mos_MailHub with(nolock) where mhb_discontinued=0 and mhb_countryid=isnull(null,mhb_countryid))and
cd.cdr_origincentreid=isnull(null, cd.cdr_origincentreid )and
cd.cdr_origincentreid in (select mhb_id from mos_MailHub with(nolock) where mhb_discontinued=0 and mhb_countryid=isnull(null,mhb_countryid)) and
convert(varchar(12),cd.cdr_reportingfrom,101)>= convert(varchar(12),convert(datetime,'1/1/2009'),101) and
convert(varchar(12),cd.cdr_reportingto,101)<=convert(varchar(12),convert(datetime,'12/31/2009'),101)
group by cd.cdr_reporttype,mo.mhb_code having cdr_reporttype='D'
--order by cd.cdr_reporttype, m.mhb_code
this is query i am formed.
but result is below
C KUL 0.000 2.974 0.000 2.974
C MAA 0.000 4.038 0.000 4.038
C SGM 0.000 1.782 0.000 1.782
C SYD 5.511 8.786 66.259 80.556
D AKL 0.000 1.782 0.000 1.782
D HKG 0.000 0.000 66.259 66.259
D SGM 5.511 15.798 0.000 21.309
how to display this report.
Please Help Me