Wednesday 15 May 2013

sql server - What is an alternative to using subqueries in this SQL query that will give us better performance? -


We have a Transaction-SQL query including Sbkwarijh, where section. Inner jobs include unwanted results add to several times Torder fees field, so we resorted to (poorly) sub-queries. It is often time consuming, we need a single result but with better performance. Any suggestions?

  amount change (cast ((in tOrders.TotalCharges, '$', '' as money))) from [ArtistShare] as TotalCharges. [Dbo] .tOrders ou tOrders IsGiftCardRedemption = 0 and = 0 and select ((tORderDetails where tORderDetails.ORderID = tORders.ORderID and tOrderDetails.isPromo = select count (tORderDetails.ID) by 1) 0 tOrders.isTestOrder = and tOrders.LastDateUpdate @startDate and @EndDate and where tProjects top 1 tProjects.ProjectReleaseDt tOrderDetails.ProjectID = tProjects.ID between tOrderDetails.OrderID = join tOrderDetails) & gt on tOrders.OrderID; = @startDate of  

However, I think that EXISTS The best performance can be, you can also consider the following approach when you mention your question in your query, it is probably because you have more than one tordaid record so that you can give them a group by Needed to abbreviate with "unwanted results of adding tOrderDetails multiple times Is debt ". Rather than using a correlated sub query that is very inefficient, use a single sub query with interiors like it.

  Select the amount (cast (Change (tOrders. TotalCharges, '$', '' in the form of funds)) [ArtistShare] as TotalCharges. [Dbo] .tOrders include interiors (tOrderDetails d on the inside d.ProjectID = p.ID Where d.isPromo joins tProjects P> Select OrderID from P = 0 and p.ProjectReleaseDt> @startDate Group Order ID) Qualifying Order on orderers Order ID = Top.OrderAid where topper.Giftcard redemption = 0 and toppers.estestorder = 0 and top.latadates @startdate and @edendet between  / Pre> 

Then, you EXISTS It should be seen from the perspective that who performs better and what you are trying to achieve is the most wiser.


No comments:

Post a Comment