I have below query ,which is taking 8 second in executing, so what should i do to reduce executing time,
with CTE_I as (
Select CodeItem,Descriptionitem from ItemMasterFile ),
Cte_S as (Select CodeItem,S.Order_Ref_No,orderqty,S.OrderNo from SalesOrder S inner join OrderDetail D on S.OrderNo=D.OrderNO
where S.Status='Open' and d.Del_ID is null),
Cte_P as (Select Codeitem,sum(prdqty) Prdqty from Probale
where DelID is null and OrderNo=17576
group by Codeitem ),
Cte_Pk as ( select D.Codeitem,M.OrderNo,sum(D.qty)PK_QTY from tbl_BalPacM M
inner join tbl_PckDetail D on M.PID=D.PID
where D.DelID is null and M.Del is null and M.OrderNo=17576
Group by D.Codeitem,M.OrderNo
)
,Cte_F as (
select Descriptionitem,orderqty,Prdqty,PK_QTY ,isnull(Orderqty-Prdqty,0) Pending from cte_I I left join Cte_S O on O.CodeItem=I.Codeitem
left join Cte_P P on P.codeitem=I.Codeitem
left join Cte_Pk PK on PK.Codeitem=I.CodeItem
where O.OrderNo=17576)
Select Descriptionitem,orderqty,Pending,Prdqty,PK_QTY from Cte_F
UNION
Select '',Sum(orderqty),Sum(Pending),sum(Prdqty),Sum(PK_QTY) from Cte_F
order by Descriptionitem asc