Search code examples
databasejoinssmsdata-warehousesql-server-data-tools

Is it possible to join merge same databases columns in SSIS?


I have one database called Customer, I have 3 tables who are important, those are: CustomerID, CustomerToBillID and CustomerName. lets say we have a data set:

CustomerID = 1 with, CustomerName = John 
CustomerID = 2 CustomerName = Bert  
And the CustomerToBillID = 2 on both (so Bert only pays)

Is there a way that I can have two CustomerName columns? for example I want to use CustomerID with CustomerName and CustomerToBillID with CustomerName.

I tried to use a data conversion for CustomerName to make CustomerNameOne and mergejoin after sorting on CustomerToBillID,but this won't do it because he will be confused about the two CustomerName from the same database and just pick one CustomerID or CustomerToBillID, I use SSIS in virtual studio 2017 SSDT.

I can provide more information if needed.

EDIT: i want to output the following:

before Before

AfterAfter. Red circle has the wrong data. It has the CustomID 454 and not 401 Customer has now CustomerName and Bill to customer has the column CustomerNameOne.

EDIT 2: right now This is how it is at the moment, the red circle are the same databases/tables, so getting CustomerName column from the second one will make it confused I think?

Edit 3: simple

to make it somewhat simple I want to do this, but this does not work because when CustomerID = 1 hits CustomerToBill = 1 then he will take CustomerID = 129 and change 1 too id 129, example in the following data result image: result

In the red line it should be (head Office) not (Mineral Hills)

EDIT 4: ??

as for the comments i did what you asked only the blue lines give me the good output but the red lines are not corresponding to the BillTOID it just says the name of the CustomerID.


Solution

  • To do this, start with two Merge Joins, one with CustomerID to CustomerName and the other join using CustomerBillToID and CustomerName. After this, add a third Merge Join using whatever unique key identifies that row (customer, order, etc.) and then you can output the only the necessary columns, including each CustomerName, from the prior joins. You'll probably also want to alias each CustomerName appropriately as well.