Hi angel
Index spool/eag 29% Filter 20 % Index =vd_ix_vd_acc_code
Index spool/eag 29% Filter 20% Index =vd_ix_vd_acc_code
Main Topics
Browse All TopicsSql Server 2000
I have written a query.
It is working and it brings correct result.
It is taking some time and I feel that the query could be made faster.
The table vd 400,000 rows and the table chartofacc has 8000 rows.
Here is my query
select acc_code = x.acc_code
, acc_name = x.acc_name
, Data = x.Data
, UnitName = (Select company_abbr from company where company_code='01')
, Group5 = x.group5
, Group7 = x.group7
from
(
select distinct
a.acc_code
, acc_name = (case levels
when 2 then space(5) + a.acc_name
when 3 then space(10) + a.acc_name
when 4 then space(15) + a.acc_name
when 5 then space(20) + a.acc_name
else a.acc_name end)
, Data= ( select TOP 1 1 from vd where vd.acc_code=a.acc_code and vd.company_code ='01')
, Group5 = ( select TOP 1 1 from vd
where left(vd.acc_code,5) = left(a.acc_code,5) and vd.company_code ='01'
and len(a.acc_code)=5)
, Group7 = ( select TOP 1 1 from vd
where left(vd.acc_code,7) = left(a.acc_code,7) and vd.company_code ='01'
and len(a.acc_code)=7)
from chartofacc a
where ( left(a.acc_code,2) in ('41','42','43','44','45',
)x
where ( x.data = 1 or ( isnull(x.group5,0)+isnull(
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
In vd the length of acc_code is exactly 11, only group level.
Here is a picture of some data of only acc_code,acc_name brought by the above query.
acc_code acc_name
41110 STORES AND SPARES - CLOSING STOCK
4111010 OPENING STOCK STORES AND SPARES
41110100005 Opening Stock Stores and Spares
4111011 STORE INVENTORY ( PURCHASE )
41110110013 Store Purchase (Local)
41120 PACKING MATERIALS-CLOSING STOCK
4112010 OPENING STOCK PACKING MATERIAL
41120100005 Opening Stock Packing Material
42110 YARN CLOSING STOCK SDM
4211010 YARN OPENING STOCK
42110100005 Opening Stock Yarn
42120 DYES AND CHEMICAL CONSUMED
4212010 OPENING STOCK DYES AND CHEMICAL
42120100004 Dyes & Chemical Purchase (Local)
42120100005 Opening Stock Dyes & Chemical
43110 WORK IN PROCESS CLOSING STOCK
4311010 WORK IN PROCESS CLOSING STOCK
43110100005 Work in Process Closing Stock
44110 FINISHED STOCK SDM
4411010 OPENING STOCK FINISHED GOODS
44110100001 Opening Stock Finished Goods
44115 FINISHED STOCK - STPL
4411510 CLOSING STOCK - STPL
44115100005 Closing Stock - Tinplate
59110 STORES AND SPARES - CLOSING STOCK
5911020 STORE PURCHASES
59110200005 Store Purchases (Local)
59110200010 Store Purchases (Imported)
59110200011 Air & Oil filters Group (Imported)
59110200999 Closing Stock Store & Spares
59110209999 Discount Store Purchase (Local Purchase)
5911025 Store Purchase Inter Co.
59110250005 G. I. Sheets - Inter Co. (Tinplate)
can you upload the execution plan picture somewhere (www.ee-stuff.com), please?
I have uploaded the file
http://www.ee-stuff.com/Ex
as you can see on the execution plan, you have a clustered index scan on the 2 tables, which return huge arrows, which get filtered later to return only few rows (small arrow). so you don't have appropriate indexes
I have to assume that this comes from this pare:
where left(vd.acc_code,5) = left(a.acc_code,5) and vd.company_code ='01'
the left() function will make it impossible to use a normal index.
you should think about either splitting the 2 fields into 2x2 fields, by putting the 5 first characters to the first field and the rest to the second field.
if you want the full acc_code field to maintain, drop it once you made the split, and add it as computed field.
you can then index the 2 parts (or, the first field), and make the query/join using that field.
alternatively, you could add a computed field to the table that returns only the 5 first characters of acc_code, and put a simple index on that computed field. then, change the query to do the join using that field.
the performance should get better dramatically.
Business Accounts
Answer for Membership
by: angelIIIPosted on 2007-01-25 at 02:07:01ID: 18394189
I guess there are missing indexes in regards to your query.
what is the execution plan?