SQL - Retrieving the most recent receipt info for an item
It's been quite a while since I have posted a SQL script, and it's funny, because this is what I had in mind when I started out my blog. Shaun Childers posted a question on the Microsoft Dynamics GP public newsgroup , as follows: "We are trying to create a script that will pull together our most recent purchasing information only. The results should give all inventory items with a qty on hand > 0, the current cost (we are average perpetual), the most recent receipt number, the unit cost for that receipted item, the receipt date, and the vendor name. I have tried to put this together, but have been unsuccessful." At first, this query may not seem to complex, but when you start to analyze the information being requested, it becomes apparent that using a standard set based query is not going to be as simple. Luckily enough, we can take advatage of the latest T-SQL enhancements to use ranks and partitions on sets to deliver the requested query, as follows: -- Created