Below is some code that I have written. In the end I will be populating the first four pricing fields and I am currently working on #1 which is called FCMP. The code has no errors but it never finishes. If I take each individual select it runs pretty quickly. I must have some incorrect logic I am not seeing. I am currently trying to populate usable cost to calculate and set that FCMP Price. My problem is definitely something with my select inside my select:
Select u.UCost from dbo.Pricing_UsableCostData u (nolock) where pr.Usku = u.USku) as UsableCost
because if I just change the select to say 2 as UsableCost it runs fine.
TRUNCATE TABLE TD_REPORTS.dbo.Flynns_CalcPricing
INSERT INTO TD_REPORTS.dbo.Flynns_CalcPricing(USku,FCMP,AveRetPrice,LowestPrice,MaxGP,NewStore,FPrice6,FPrice7,FPrice8,FPrice9,FPrice10)
Select TD_SOURCE.dbo.Sku.SkuCode,0,0,0,0,0,0,0,0,0,0 from TD_SOURCE.dbo.Sku
-- Create and Update Flynns_CalcPricing from INV_SKU
-- CalcIt is USku, Manufacturer,Line,UsableCost,Multiplier
Update TD_REPORTS.dbo.Flynns_CalcPricing
SET FCMP =
CASE
WHEN CalcIt.Cman = 'Michelin' then ((UsableCost + 44) * CalcIt.Multiplier) -- Add All Mans and some Lines (Lines before just Mans)
WHEN CalcIt.UsableCost > 0 and CalcIt.UsableCost <= 40.99 then ((UsableCost + 32) * CalcIt.Multiplier)
WHEN CalcIt.UsableCost >= 41 and CalcIt.UsableCost <= 45.99 then ((UsableCost + 34) * CalcIt.Multiplier)
WHEN CalcIt.UsableCost >= 46 and CalcIt.UsableCost <= 50.99 then ((UsableCost + 36) * CalcIt.Multiplier)
WHEN CalcIt.UsableCost >= 51 and CalcIt.UsableCost <= 55.99 then ((UsableCost + 38) * CalcIt.Multiplier)
WHEN CalcIt.UsableCost >= 56 and CalcIt.UsableCost <= 60.99 then ((UsableCost + 40) * CalcIt.Multiplier)
WHEN CalcIt.UsableCost >= 61 and CalcIt.UsableCost <= 65.99 then ((UsableCost + 42) * CalcIt.Multiplier)
WHEN CalcIt.UsableCost >= 66 and CalcIt.UsableCost <= 70.99 then ((UsableCost + 44) * CalcIt.Multiplier)
WHEN CalcIt.UsableCost >= 71 and CalcIt.UsableCost <= 75.99 then ((UsableCost + 45) * CalcIt.Multiplier)
WHEN CalcIt.UsableCost >= 76 and CalcIt.UsableCost <= 80.99 then ((UsableCost + 46) * CalcIt.Multiplier)
WHEN CalcIt.UsableCost >= 81 and CalcIt.UsableCost <= 85.99 then ((UsableCost + 47) * CalcIt.Multiplier)
WHEN CalcIt.UsableCost >= 86 and CalcIt.UsableCost <= 90.99 then ((UsableCost + 48) * CalcIt.Multiplier)
WHEN CalcIt.UsableCost >= 91 and CalcIt.UsableCost <= 95.99 then ((UsableCost + 49) * CalcIt.Multiplier)
WHEN CalcIt.UsableCost >= 96 and CalcIt.UsableCost <= 100.99 then ((UsableCost + 50) * CalcIt.Multiplier)
WHEN CalcIt.UsableCost >= 101 and CalcIt.UsableCost <= 109.99 then ((UsableCost + 51) * CalcIt.Multiplier)
WHEN CalcIt.UsableCost >= 110 and CalcIt.UsableCost <= 119.99 then ((UsableCost + 52) * CalcIt.Multiplier)
WHEN CalcIt.UsableCost >= 120 and CalcIt.UsableCost <= 129.99 then ((UsableCost + 53) * CalcIt.Multiplier)
WHEN CalcIt.UsableCost >= 130 and CalcIt.UsableCost <= 139.99 then ((UsableCost + 54) * CalcIt.Multiplier)
WHEN CalcIt.UsableCost >= 140 and CalcIt.UsableCost <= 149.99 then ((UsableCost + 55) * CalcIt.Multiplier)
WHEN CalcIt.UsableCost >= 150 and CalcIt.UsableCost <= 159.99 then ((UsableCost + 56) * CalcIt.Multiplier)
WHEN CalcIt.UsableCost >= 160 and CalcIt.UsableCost <= 169.99 then ((UsableCost + 57) * CalcIt.Multiplier)
WHEN CalcIt.UsableCost >= 170 and CalcIt.UsableCost <= 179.99 then ((UsableCost + 58) * CalcIt.Multiplier)
WHEN CalcIt.UsableCost >= 180 then ((UsableCost + 59) * CalcIt.Multiplier) -- Truncate and add .98
END,
AveRetPrice = 1,
LowestPrice = 2,
MaxGP = 3,
NewStore = 4
From
(
SELECT
pr.USku,
s.Manufacturer as Cman,
(Select u.UCost from dbo.Pricing_UsableCostData u (nolock) where pr.Usku = u.USku) as UsableCost,
1 as multiplier
FROM
TD_REPORTS.dbo.Flynns_CalcPricing pr (nolock)
inner join
TD_SOURCE.dbo.SkuMaster s (nolock)
ON pr.USku = s.SkuCode
)CalcIt