I know this is something to do with the database design. I have this querry from my friend, this will be used for a report. All the necessarry datas on it, is get from 4 tables. Since the requisition of the report is very complex because this report was not identified on the design phase of the development. So, we put the necessarry querries on a view, and all of the datas are get in there. However he still have to query on that view to specified the necessarry data for the specific column of the report. He is concern now how would he will make this querry a little bit faster?Any suggestion will be much appreciated... THNX...CREATE PROCEDURE dbo.spe_StockInventory_Balance @xMonthFrom as char(12), @xMonthTo as char(12)ASBEGINselect StockCode, CompleteDescription, --StockCode & CompleteDescription,(select top 1 isnull(EndingQty,0) from vwStockwhere StockCode = AAA.StockCode and DateTimeOrder < cast(@xMonthFrom as DateTime) --Beginning Quantity,----------------order by DateTimeOrder desc, TransID desc) as BeginningQty, (select top 1 isnull(EndingAmount,0) from vwStockwhere StockCode = AAA.StockCode and DateTimeOrder < cast(@xMonthFrom as DateTime) --Beginning Amount--------------order by DateTimeOrder desc, TransID desc) as BeginningAmount, (select isnull(sum(Quantity),0) from vwStockwhere StockCode = AAA.StockCode and DateTimeOrder >= cast(@xMonthFrom as DateTime) and DateTimeOrder < cast(@xMonthTo as DateTime) and type =0) as SRR_Qty, ---S.R.R. Quantity---------------------(select isnull(sum(Amount),0) from vwStockwhere StockCode = AAA.StockCode and DateTimeOrder >= cast(@xMonthFrom as DateTime) and DateTimeOrder < cast(@xMonthTo as DateTime) and type =0) as SRR_Amnt, ---S.R.R. Amount---------------------(select isnull(sum(Quantity),0) from vwStockwhere StockCode = AAA.StockCode and DateTimeOrder >= cast(@xMonthFrom as DateTime) and DateTimeOrder < cast(@xMonthTo as DateTime) and type =1) as MIS_Qty, ----M.I.S. Quntity,------------------------(select isnull(sum(Amount),0) from vwStockwhere StockCode = AAA.StockCode and DateTimeOrder >= cast(@xMonthFrom as DateTime) and DateTimeOrder < cast(@xMonthTo as DateTime) and type =1) as MIS_Amnt, --- M.I.S. Amount----------------------(select top 1 isnull(EndingQty,0) from vwStockwhere StockCode = AAA.StockCode and DateTimeOrder < cast(@xMonthTo as DateTime) -----Ending Qunatity---------------order by DateTimeOrder desc,TransID desc) as EndingQty,(select top 1 isnull(EndingAmount,0) from vwStockwhere StockCode = AAA.StockCode and DateTimeOrder < cast(@xMonthTo as DateTime) -----Ending Amount--------------order by DateTimeOrder desc, TransID desc) as EndingAmountfrom tblMasterProfile as AAA--where flgSelectedToConsumption = 1 order by Category ascENDGO
Want Philippines to become 1st World COuntry? Go for World War 3...