IF (EXISTS (select Table_name from SysTable where LCase(Table_name)=LCase('v_GeneralReportServices'))) THEN Drop View v_GeneralReportServices END IF GO create VIEW "DBA"."v_GeneralReportServices" as select ServiceName=Services.ServiceName, DayIncomes=Sum(if Invoices.InvoiceDateDt=bvrData2 then Round(Articles.TotalSum*(1+VR.Rate),4) else 0 endif), MonthIncomes=Sum(if Month(Invoices.InvoiceDateDt)=Month(bvrData2) then Round(CalcPriceWithDiscount(Articles.Discount,Articles.Price*Articles.Qty)*(1+VR.Rate*(if TipDDS=2 then 1 else 0 endif)),4) else 0 endif), PercentDayMonth=if MonthIncomes<>0 then Round(((DayIncomes/MonthIncomes)*100),1) /* v[17.05.2005 ] Jorko v MonthIncomes vzema pod vnimanie dali sdelkata e s DDS ili ne*/ else '-' endif from "dba".Invoices,"dba".Services,"dba".Articles,"dba".VATRates as VR where Invoices.InvoiceNo=Articles.InvoiceNo and Articles.ServiceNo=Services.ServiceNo and VR.DDSType=Articles.DDSType group by ServiceName