Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
vyx
Starting Member
2 Posts |
Posted - 2012-07-07 : 06:29:04
|
Hello GuysI just want to view the Transaction of the 3 tables at first the result of query display fast but when it data inserted increase takes too long to display and shows a message that says timeout expired...How could i simplify and speedup this query to display data very fast..tblItems=5500 recordtblitemledger=20000 records tblwarehousing=10000 recordsselect i.itemid,i.description,isnull(i.conversion,1)as conversion,isnull(i.bigunit,'PCS')AS BigUnit,isnull(i.itemsection,0)as Itemsection,isnull(i.smallunit,'PCS')as SmallUnit,isnull(isnull(i.costsmall,0),0) as costsmall,isnull(isnull(i.costBig,0),0) as costBig,isnull(isnull(i.bulkprice,0),0) as bulkPrice,isnull(isnull(i.sellingprice,0),0) as sellingprice, [QTYIN] = ISNULL((select SUM(QTYIN*CONVERSION) FROM TBLITEMLEDGER WHERE deptcode='GROCERY' and TRANSDATE<='7/6/2012' and itemid = I.ITEMID),'0'), [QTYOUT] = ISNULL((select SUM(QTYOUT*CONVERSION) FROM TBLITEMLEDGER WHERE deptcode='GROCERY' and TRANSDATE<='7/6/2012' and itemid = I.ITEMID),'0'), [BALANCE]=ISNULL((select SUM(QTYIN*CONVERSION)-SUM(QTYOUT*CONVERSION) FROM TBLITEMLEDGER WHERE deptcode='GROCERY' AND TRANSDATE<='7/6/2012' and itemid = I.ITEMID),'0')[PurchaseCost]=ISNULL((select SUM(ISNULL(TotPurchaseCost,0)) FROM TBLITEMLEDGER WHERE deptcode='GROCERY' AND TRANSDATE<='7/6/2012' and itemid = I.ITEMID),'0'), [SalesCost]=ISNULL((select SUM(ISNULL(TotSalesCost,0)) FROM TBLITEMLEDGER WHERE deptcode='GROCERY' AND TRANSDATE<='7/6/2012' and itemid = I.ITEMID),'0'), [SalesPrice]=ISNULL((select SUM(ISNULL(TotSalesPrice,0)) FROM TBLITEMLEDGER WHERE deptcode='GROCERY' AND TRANSDATE<='7/6/2012' and itemid = I.ITEMID),'0') FROM tblitems i inner join tblwarehousing w on i.itemid=w.itemid where w.deptcode='GROCERY' order by I.DESCRIPTIONI really appreciate all your help here.. Thank you in advance. |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-07-07 : 08:40:04
|
Two or three things to look at:a) What kind of primary keys and indexes do you have on the tables? Specifically, do you have indexes on the itemid columns of each table? If not having those should speed it up.b) Instead of using the sub-queries to compute the sums, if you can join the table TBLITEMLEDGER to the other 2 tables that should help. I don't know enough about your data to be able to suggest how to do that get the correct grouping. |
|
|
vyx
Starting Member
2 Posts |
Posted - 2012-07-08 : 02:56:35
|
Thank you for your reply... The tblitems has a primarykey ITEMIDtblitemledger has no primary key as well as the tblwarehousing but they have a automatic number pkeyno identity autothe sample database looks like thisTBLITEMS(5000 records)=========================================================================================================ITEMID |DESCRIPTION |CONVERSION |BIGUNIT |SMALLUNIT |SECTION |COSTBIG |COSTSMALL |BULKPRICE |SELLINGPRICE100 A 10 pck pcs 2 50 5 55 7 200 A 10 pck pcs 2 50 5 55 7 300 A 10 pck pcs 2 50 5 55 7 400 A 10 pck pcs 2 50 5 55 7 500 A 10 pck pcs 2 50 5 55 7 TBLWAREHOUSING(10000 Records doubled the tblitems)ITEMID|DEPTCODE================100 DEPTA200 DEPTA300 DEPTA400 DEPTA500 DEPTA100 DEPTB200 DEPTB300 DEPTB400 DEPTB500 DEPTBTBLITEMLEDGER(20 0000 of records)================ITEMID|QTYIN|QTYOUT|TOTSALESCOST|TOTSALESPRICE TRANSDATE100 1 0 5 5 01/01/2012100 1 0 5 5 01/01/2012100 1 0 5 5 02/02/2012200 1 0 5 5 02/02/2012200 1 0 5 5 03/03/2012200 1 0 5 5 03/04/2012200 1 0 5 5 04/01/2012300 1 0 5 5 04/01/2012300 1 0 5 5 05/01/2012300 1 0 5 5 05/01/2012400 1 0 5 5 06/01/2012400 1 0 5 5 06/01/2012100 1 0 5 5 07/06/2012100 1 0 5 5 07/06/2012200 1 0 5 5 07/06/2012I Just made a sample data that looks like on my records, when i execute the query it takes too long that result for timeout in my application and in sql server 2005 IDE. executing and processing too long that cause me to stop the executionHope it helps you figure out my concern.Thanks again in advance |
|
|
|
|
|
|
|