Using a Loop to Exclude Records

  • 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?

    countryskucustomerunitssalesunit priceAverage Selling Price

    usaaguirre101001015.55555556

    usawirt100200020

    usaemrich35016.66667

    usbaguirre341002.9411769.190627744

    usbwirt67200029.85075

    usbemrich34501.470588

    usbjory20502.5

    ?

  • 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.


    - 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.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

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

    The attached Excel file appears to have become detached.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • This is an office request, not homework.

    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.

    Thanks

  • In order to help we will need a few things:

    1. Sample DDL in the form of CREATE TABLE statements

    2. Sample data in the form of INSERT INTO statements

    3. Expected results based on the sample data

    Please take a few minutes and read the first article in my signature for best practices when posting questions.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply