I am looking for suggestions on how best to solve this problem. I need to create a stored proc that finds the last 5 times a certain type of item was ordered and caclulate the average price.
My first thought was to make a temp table with a list of the desired items then somehow loop through them and use the item as the criteria to find the last 5 purchases and append the results into a table. I am not sure how to loop like that using a temp table inside a stored proc.
After reading thread183-1381093 I as wondering if there was a more "elegent" sql solution that I can achive with some combination of join types and sub queries. The trick again is that I only want the last 5 purchases. Any suggestions?
Thank You,
sabloomer
My first thought was to make a temp table with a list of the desired items then somehow loop through them and use the item as the criteria to find the last 5 purchases and append the results into a table. I am not sure how to loop like that using a temp table inside a stored proc.
After reading thread183-1381093 I as wondering if there was a more "elegent" sql solution that I can achive with some combination of join types and sub queries. The trick again is that I only want the last 5 purchases. Any suggestions?
Thank You,
sabloomer