vistadb4 not recognize this sql view script. but it is working with sql2005. is there a solution ? thanks.
SELECT DISTINCT ItemCode, SellingPrice
FROM         dbo.SalesPurchases AS a
WHERE     (KeyID =
                          (SELECT     TOP (1) MAX(KeyID) AS KeyID
                            FROM          dbo.SalesPurchases AS b
                            GROUP BY ItemCode, Type
                            HAVING      (ItemCode = a.ItemCode) AND (Type = 'purchase')))
GROUP BY ItemCode, SellingPrice
				
                        
not sure but take a look at this: