jadams0173
Technical User
- Feb 18, 2005
- 1,210
Hey all. I'm using sql 2000.
I have a query that I need to speed up. It only takes about 3 seconds to run it but I'm running in a cursor at the moment..I know that's bad.
It takes about 26 minutes to run and need to reduce that as much as possible. I'd post the execution plan but I'm not sure how to as it is pretty large.
There is a Hash match/right outer join and a Parallelism/repartion streams that each to 32% of the total time.
Here is the query.
I have a query that I need to speed up. It only takes about 3 seconds to run it but I'm running in a cursor at the moment..I know that's bad.
It takes about 26 minutes to run and need to reduce that as much as possible. I'd post the execution plan but I'm not sure how to as it is pretty large.
There is a Hash match/right outer join and a Parallelism/repartion streams that each to 32% of the total time.
Here is the query.
Code:
[COLOR=blue]Set[/color] [COLOR=#FF00FF]Nocount[/color] [COLOR=blue]On[/color]
[COLOR=blue]Declare[/color] @Qty [COLOR=blue]int[/color],
@ChildPN [COLOR=blue]Varchar[/color](25),
@HLAPlanned [COLOR=blue]int[/color],
@LLARemain [COLOR=blue]int[/color],
@Unallocated [COLOR=blue]int[/color]
[COLOR=blue]Set[/color] @Qty = 1[COLOR=green]--@pQty
[/color][COLOR=blue]Set[/color] @ChildPN = [COLOR=red]'123456R'[/color][COLOR=green]--@pChildPN
[/color]
[COLOR=green]--LLA Required (Sum HLA needs)
[/color][COLOR=blue]Select[/color] @HLAPlanned = sum(([COLOR=#FF00FF]coalesce[/color](b.RelPlan,0)* @Qty + [COLOR=#FF00FF]coalesce[/color](a.ATR,0)*@Qty) + [COLOR=#FF00FF]coalesce[/color](a.WIP,0) + [COLOR=#FF00FF]coalesce[/color](OpenPicks,0) + [COLOR=#FF00FF]coalesce[/color](c.IndDmdQTY,0))
[COLOR=blue]FROM[/color] V_Parent_Child_No_Ind_demand_JH a
[COLOR=blue]inner[/color] [COLOR=blue]join[/color]
(
[COLOR=blue]Select[/color] Parent "ParentPN"
[COLOR=blue]from[/color] V_Parent_Child_No_Ind_demand_JH
[COLOR=blue]where[/color] item = @ChildPN
) [COLOR=blue]d[/color]
[COLOR=blue]on[/color] a.Item = [COLOR=blue]d[/color].ParentPN
[COLOR=#FF00FF]left[/color] [COLOR=blue]join[/color] ReleasePlan b
[COLOR=blue]on[/color] a.Item = b.Item
[COLOR=#FF00FF]left[/color] [COLOR=blue]join[/color] IndDemand c
[COLOR=blue]on[/color] a.item = c.ChildPN
[COLOR=green]--this is the remaing qty of child Pn's that haven't been consumed
[/color][COLOR=blue]Select[/color] @LLARemain = LLARemain [COLOR=blue]from[/color] LLAPlanned [COLOR=blue]Where[/color] ChildPN = @ChildPN
[COLOR=blue]Set[/color] @UnAllocated = @LLARemain - @HLAPlanned
[COLOR=blue]Update[/color] LLAPlanned
[COLOR=blue]Set[/color] LLARemain = @Unallocated
[COLOR=blue]Where[/color] ChildPN = @ChildPN