Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Query Help with getting the min value

Author  Topic 

Diesel00
Starting Member

6 Posts

Posted - 2014-02-07 : 12:10:45
I have to get the min price value V.Price for each P.PartID but the PartID can have for than one price value.

Below is what I have so far Also I am getting other FRID besides 0 as well.

Please help

Select P.PartID, P.mansPart, P.Cost As PartCost, V.PartID, V.PartNo, V.price As VendPrice, M.title, C.CoName, P.FRID
From Parts As P
Right Join Vend2Part As V
On P.PartID = V.PartID And P.FRID = V.FRID
Left Join companies As C
On C.COID = V.COID And C.FRID = V.FRID
Left Join db_manuf As M
On P.manufacturer = M.ManID
Where P.FRID = 0 And P.cost > (V.price * 1.02) or P.cost < (V.price * 0.98) And V.price = (Select Min(Price) From Vend2Part)
Order By P.FRID

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-02-07 : 15:44:19
Sample data? Expected output? Here are some link to help you with supplying that information:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page
   

- Advertisement -