Siva has also dropped a new SQL Script for Last Cost Price of Items on us in a new post.
SQL Script for Last Purchase Cost of Items
Sales, Purchasing & InventorySQL & DataDevelopment & Integration
Archived post from 2010. Dynamics GP and the links it points to have changed since; check current documentation before relying on version-specific steps.