Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here Bold code is main issue for slow fetching

C#
Select distinct isnull(V.VendorItemId,0) as VendorItemId  , isnull(V.VendorItemNumber,I.Ord_guide) as VendorItemNumber,
isnull(V.VendorItemDescription,I.Pkg_desc) as VendorItemDescription,
Id=(select Min(k.Id) from dbo.InvoiceImportDataPrice k where K.Ord_guide=I.Ord_guide and K.Price=I.Price
and k.Pkg_desc=I.Pkg_desc and k.Store_name=I.Store_name and k.InvoiceImportHistoryId = 128),
I.InvoiceImportHistoryId,I.Price,isnull(V.CurrentPrice,0) as CurrentPrice,ISNULL(ISNULL(V.CurrentPrice, 0) - ISNULL(I.Price, 0), 0) AS differencePrice,
I.Invoice_No, I.Sold_to, I.Store_name, I.Deliv_date,
(  CASE WHEN isnull(I.Qty_ship,'0')='0' THEN '-0' else I.Qty_ship   END ) AS Qty_ship, I.Ship_um, 
(  CASE WHEN isnull(I.Qty_ord,'0')='0' THEN '-0'  else I.Qty_ord   END ) AS Qty_ord,  I.Item_no, I.Weight, 
(  CASE WHEN isnull(I.Amount,'0')='0' THEN '-0'  else I.Amount   END ) AS Amount, I.Pkg_desc, I.Tax_amount, I.Ord_guide
,(select count(*) FROM dbo.InvoiceImportDataPrice IP where IP.Pkg_desc=V.VendorItemDescription
and IP.Item_no= V.VendorItemNumber and  IP.Price = V.CurrentPrice)
as PriceDiscrepancyCount
from dbo.InvoiceImportDataPrice  I
left join dbo.VendorItems V WITH (NOLOCK) on V.VendorItemNumber = I.Ord_guide
where (I.InvoiceImportHistoryId = 128 and VendorItemDescription != '"Sales Tax"') or
(I.InvoiceImportHistoryId = 128 and isnull(V.VendorItemDescription,'')='')


What I have tried:

when i off both code then data fetch fast but i need both code. total no of records is 2833
Posted
Updated 3-Aug-16 20:55pm
v3

1 solution

There can be a ton of different things wrong here.
  • Collation

  • No covering Indexes on the subqueries

  • Joining on large nvarchar columns are not recommented at all

  • Statistics

you name it..
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900