Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Using a Loop to Exclude Records Expand / Collapse
Author
Message
Posted Thursday, June 20, 2013 5:28 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, October 9, 2013 1:17 PM
Points: 3, Visits: 9
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?


country sku customer units sales unit price Average Selling Price
us a aguirre 10 100 10 15.55555556
us a wirt 100 2000 20
us a emrich 3 50 16.66667
us b aguirre 34 100 2.941176 9.190627744
us b wirt 67 2000 29.85075
us b emrich 34 50 1.470588
us b jory 20 50 2.5


?
Post #1466000
Posted Thursday, June 20, 2013 5:43 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 10:03 PM
Points: 6,249, Visits: 7,404
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.


country sku customer units sales unit price Average Selling Price
us a aguirre 10 100 10 15.55555556
us a wirt 100 2000 20
us a emrich 3 50 16.66667
us b aguirre 34 100 2.941176 9.190627744
us b wirt 67 2000 29.85075
us b emrich 34 50 1.470588
us b jory 20 50 2.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 | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
Post #1466008
Posted Friday, June 21, 2013 12:27 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 2:06 PM
Points: 5,047, Visits: 11,797
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.



Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.
Post #1466060
Posted Friday, June 21, 2013 11:35 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, October 9, 2013 1:17 PM
Points: 3, Visits: 9
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
Post #1466324
Posted Friday, June 21, 2013 12:51 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:21 AM
Points: 13,302, Visits: 12,161
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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1466351
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse