Question

So, not sure how to explain this but here goes. I am trying to translate a table of commissions earned. Some of the records have the same invoice and item meaning multiple people earned commissions on that product. I want to merge those records so I only have one record per product per invoice. Basically, like a pyramid scheme, salespeople make commissions on sales and depending on what level they are at, (1,2,3,4) all salespeople above them get a commission as well. So I need to find records where invoice and item are the same, pull data from each of those records and then output only one record with that data.

I am pretty sure a script component is the way to go but I am not sure how to pull multiple rows of data in to check for duplicate invoice and item, also keeping some of the data for each row to output together.

Let me know if you have any questions, I know I didn't word that the best.

The source table looks like this

COMMISSION Table

 SalespersonID - the person getting the commission
 InvoiceID - ID of invoice
 ItemID - ID of specific lineitem on invoice
 ProductID - ID of product sold
 Sales_Amt - total for that lineitem
 Salesperson Downlevel ID - ID of salesperson below SalespersonID if exists
 Commission Rate - percentage Salesperson receives 
 Commission Total - amt salesperson receives

There are some other columns but these are the important ones.

I am translating this into a table that looks like this

New COMMISSION Table

 CommissionId - Primary key for commission table
 CommissionPayable - amt salesperson gets
 CommissionPayableUpline1 - amt salespersonUpline1 gets
 CommissionPayableUpline2 - amt salespersonUpline2 gets
 CommissionPayableUpline3 - amt salespersonUpline3 gets
 CommissionRate - percent salesperson gets of amount
 CommissionRateUpline1 - percent salesperson upline1 gets
 CommissionRateUpline2 - percent salesperson upline2 gets
 CommissionRateUpline3 - percent salesperson upline3 gets
 SalespersonId - Id of salesperson
 SalespersonUpline1 - ID of salesperson upline1
 SalespersonUpline2 - ID of salesperson upline2
 salespersonUpline3 - ID of salesperson upline3

So you see we can have up to four levels of salespeople. Most of our salespeople are only 1 to 2 levels but we do have a few 3 levels deep and none currently that are four levels deep. The way it is stored in the old database is confusing and not very efficient.

I want to find rows with duplicate invoice and item ids, grab the salespeople, and down level salespeople as well as commission rates and amounts for each, then insert all that into one row in new system.

Was it helpful?

Solution

Well I finally got this figured out by using the ssis script component and then doing some fancy sorting and creating new records on output.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top