I need help with automating a process in SQL Server. I want to use a loop to exclude certain records.

Calculate the impact of each record to the “Average Selling Price” in the attached excel file.For example, If you were to exclude the Aguirre purchase of SKU A in the US, what would be the “Average Selling Price” for A in the US?Additionally, after itinerating over the 4 transaction for SKU B in the US, what is the ranking of each transaction regarding the impact to the ASP?

joshwirt (6/20/2013)Calculate the impact of each record to the “Average Selling Price” in the attached excel file.

Attached excel file? This sounds like homework or someone at the office asking for a very odd request.

For example, If you were to exclude the Aguirre purchase of SKU A in the US, what would be the “Average Selling Price” for A in the US?Additionally, after itinerating over the 4 transaction for SKU B in the US, what is the ranking of each transaction regarding the impact to the ASP?

These questions are overloaded, but they're also horribly out of context. How do you want to rank the impact? Largest change from the average? Largest or smallest value? There's a lot to decide there. Also, dynamic filtering is usually not simple to do via T-SQL without expectations of how you want to filter. That example isn't specific enough to setup a parameterized request against.

This is not consumable, but semi-useful as an example if you wanted short answers to your questions. The problem is, I'm not sure what the question really is. You've asked us how to use a loop. I can explain that, but I don't know what you want to DO with the loop. Not a single question above requires one... and honestly I don't want to do your homework for you if that's what that is, or puzzle out the business requirement if it's not. Define your problem in consumable format (schema/sample data), show us what you've attempted and *specifically* what you're trying to get it to do (not vague examples) and we'll help you out.

- Craig Farrell

Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

1) I am trying to figure out how to use a loop to see how the average selling price is affected if you take out one of the customer's orders. For example, if you were to exclude one of the Aguirre purchases of SKU A, what would be the “Average Selling Price” for A in the US?

2) I am trying to figure out the ranking of each order's ASP. Meaning which order's ASP affects the total ASP of the product as a whole.

Sorry for the confusion earlier. I pretty much copied and pasted his email.