The column PriceQTy from the following existing procedure will get the price that matches Quan.
for example in image 1,
quan = 5000, which matches quan1, then PriceQTy is price1 which is 35.
if Quan = 12000, which doesn't match quan1,quan2,...quan5 then PriceQty is NULL
I need to alter this procedure, if Quan doesn't match quan1, quan2..quan5, instead of showing Null, it should pick closer number from quan1, quan2...quan5.
now because Quan = 12000, the closer number is quan2 = 6000, so PriceQty should be pricelab2, which is 55 and 38.
ALTER PROCEDURE [dbo].[xx_est_estdetail_ship]
case when bbjthead.quan = aajthead.quan1 then sumqt.pricelab1
when bbjthead.quan = aajthead.quan2 then sumqt.pricelab2
when bbjthead.quan = aajthead.quan3 then sumqt.pricelab3
when bbjthead.quan = aajthead.quan4 then sumqt.pricelab4
when bbjthead.quan = aajthead.quan5 then sumqt.pricelab5
Else null end PriceQty
JOIN aajthead ON aaproces.estno = aajthead.estno
JOIN bbjthead ON aaproces.estno = bbjthead.estno
JOIN (SELECT aaprocqt.estno,
SUM(CASE aaprocqt.Qty WHEN 1 THEN pricelab ELSE 0 END) AS pricelab1,
SUM(CASE aaprocqt.Qty WHEN 2 THEN pricelab ELSE 0 END) AS pricelab2,
SUM(CASE aaprocqt.Qty WHEN 3 THEN pricelab ELSE 0 END) AS pricelab3,
SUM(CASE aaprocqt.Qty WHEN 4 THEN pricelab ELSE 0 END) AS pricelab4,
SUM(CASE aaprocqt.Qty WHEN 5 THEN pricelab ELSE 0 END) AS pricelab5
INNER JOIN bbjthead ON aaprocqt.estno =bbjthead.estno AND bbjthead.ljob = @Ljob
WHERE aaprocqt.procgroup = '8'
--and bbjthead.ljob = @tcLjob
GROUP BY aaprocqt.estno,
) sumqt ON aaproces.estno = sumqt.estno
AND aaproces.partno = sumqt.partno
AND aaproces.procgroup = sumqt.procgroup
AND aaproces.[lineno] = sumqt.[lineno]
AND aaproces.counter = sumqt.counter
WHERE aaproces.estno = bbjthead.estno
AND aaproces.procgroup = '8' and bbjthead.ljob = @Ljob 1.bmp untitled.bmp
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
-Mike Kapnisakis, Warner Bros
With your subscription - you'll gain access to our exclusive IT community of thousands of IT pros. You'll also be able to connect with highly specified Experts to get personalized solutions to your troubleshooting & research questions. It’s like crowd-sourced consulting.
We can't always guarantee that the perfect solution to your specific problem will be waiting for you. If you ask your own question - our Certified Experts will team up with you to help you get the answers you need.
Our certified Experts are CTOs, CISOs, and Technical Architects who answer questions, write articles, and produce videos on Experts Exchange. 99% of them have full time tech jobs - they volunteer their time to help other people in the technology industry learn and succeed.
We can't guarantee quick solutions - Experts Exchange isn't a help desk. We're a community of IT professionals committed to sharing knowledge. Our experts volunteer their time to help other people in the technology industry learn and succeed.