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.
countryskucustomerunitssalesunit priceAverage Selling Price
usaaguirre101001015.55555556
usawirt100200020
usaemrich35016.66667
usbaguirre341002.9411769.190627744
usbwirt67200029.85075
usbemrich34501.470588
usbjory20502.5
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.
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.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA