Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Performance puzzle
Message
De
17/04/2020 10:08:31
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Scripting
Titre:
Performance puzzle
Divers
Thread ID:
01674076
Message ID:
01674076
Vues:
60
DECLARE @startdate DATETIME
DECLARE @enddate DATETIME
select @startdate = '2020-03-31'
select @enddate = '2020-03-31'

select inv_number, billingname, bill_store, sum(charged) as charged, sum(storetax) as tax, sum(charged + storetax) as totalcharge from (  select  IIF(right(b.bill_store,6) = SPACE(6), c.name, s.store_name) AS billingname, b.* from
  (SELECT inv_number, dbo.gettaxrate(tax_area) AS taxrate, dbo.gettaxareaname(tax_area) AS taxareaname, bill_type, bill_store, tax_area, trancode, charged, storetax, storetxbl  FROM billing 
 where CONVERT(date,inv_date) >= @startdate AND CONVERT(date,inv_date) <= @enddate
 UNION ALL SELECT invno AS inv_number, dbo.GetTaxRate(1) as taxrate, dbo.gettaxareaname(1) AS taxareaname, SPACE(23) as bill_type, custno AS bill_store, 1, 'MI', invamt - tax AS charged, 
 tax as storetax, invamt - tax AS storetxble  from arinvoice  where left(invno,1) = SPACE(1) and CONVERT(date,invdte) >=(@startdate)  AND CONVERT(date,invdte) <= (@enddate)
 ) B INNER JOIN company C ON LEFT(B.bill_store,4) = c.comp_code LEFT JOIN store s ON LEFT(s.storecode,11) = b.bill_store ) i group by inv_number, billingname, bill_store order by inv_number 
in an SSMQ query this code takes under a second.
When I convert to code to a stored procedure and pass parameters, it gives the same results, but runs for 90 seconds.

Any ideas?
Anyone who does not go overboard- deserves to.
Malcolm Forbes, Sr.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform