Запрос 1:
select
PremiumYTDCurrent=Sum((AASI.Inv_Premium)*R.[Percent]),
R.STAFF, L.Description, L.LINE_OF_BUSINESS
from AAS_Invoice AASI,Invoice I,Revenue_Tracking R, Policy P, Line_Of_Business L
where I.Invoice_No=convert(Char,Convert(int,AASI.Inv_Entry_Num))
and I.Invoice=R.Invoice
and I.POLICY=P.POLICY
and L.LINE_OF_BUSINESS=P.LINE_OF_BUSINESS
and AASI.Inv_Acctcur>='201001'
and AASI.Inv_Acctcur<='201004'
and R.Organization=200
and R.Activity_type='Broker'
and R.STAFF=7600
and R.[Percent]>0
group by R.STAFF, L.Description, L.LINE_OF_BUSINESS
Запрос 2:
select
PremiumYTDPrevious=Sum((AASI.Inv_Premium)*R.[Percent]),
R.STAFF, L.Description, L.LINE_OF_BUSINESS
from AAS_Invoice AASI,Invoice I,Revenue_Tracking R, Policy P, Line_Of_Business L
where I.Invoice_No=convert(Char,Convert(int,AASI.Inv_Entry_Num))
and I.Invoice=R.Invoice
and I.POLICY=P.POLICY
and L.LINE_OF_BUSINESS=P.LINE_OF_BUSINESS
and AASI.Inv_Acctcur>='200901'
and AASI.Inv_Acctcur<='200904'
and R.Organization=200
and R.Activity_type='Broker'
and R.STAFF=7600
and R.[Percent]>0
group by R.STAFF, L.Description, L.LINE_OF_BUSINESS
Эти 2 запроса одинаковы, за исключением периода с датой. Я хотел бы иметь один запрос, но добавить к нему еще одно поле (PremiumYTDPrevious). Возможно ли это сделать?
Спасибо
Ile