Вы находитесь на странице: 1из 5

Persisting Update using SSIS

!No Actual Credit Card Number is used.


SELECT s.CreditCardNumber, s.NewDimLocationID as NewLocationID, d.Dimlocationid as OldLocationID, d.ReportingDate FROM SourceUpdate AS s LEFT OUTER JOIN DestinationUpdate AS d ON d.Creditcardnumber = s.CreditCardNumber WHERE (s.CreditCardNumber = 1234567890987654) AND (d.ReportingDate BETWEEN '2011-06-06' AND '2011-06-30') ORDER BY s.CreditCardNumber, d.ReportingDate
CreditCardNumber NewLocationID 118371 118371 118371 118371 118371 118371 118371 118371 118371 118371 118371 118371 118371 118371 118371 118371 118371 118371 118371 118371 118371 OldLocationID 125793 125793 125793 125793 125793 125793 125793 125793 125793 125793 118371 118371 118371 118371 118371 118371 118371 118371 118371 118371 118371 ReportinDate 2011-06-07 0:00:00 2011-06-08 0:00:00 2011-06-09 0:00:00 2011-06-10 0:00:00 2011-06-12 0:00:00 2011-06-13 0:00:00 2011-06-14 0:00:00 2011-06-15 0:00:00 2011-06-16 0:00:00 2011-06-17 0:00:00 2011-06-19 0:00:00 2011-06-20 0:00:00 2011-06-21 0:00:00 2011-06-22 0:00:00 2011-06-23 0:00:00 2011-06-24 0:00:00 2011-06-26 0:00:00 2011-06-27 0:00:00 2011-06-28 0:00:00 2011-06-29 0:00:00 2011-06-30 0:00:00

1234567890987654 1234567890987654 1234567890987654 1234567890987654 1234567890987654 1234567890987654 1234567890987654 1234567890987654 1234567890987654 1234567890987654 1234567890987654 1234567890987654 1234567890987654 1234567890987654 1234567890987654 1234567890987654 1234567890987654 1234567890987654 1234567890987654 1234567890987654 1234567890987654

The highlighted OldLocationID are the one that needs to be update.

Your SSIS package should be look like this: 1. Your Control Flow: (the script is for my personal testing. Just ignore it.)

- Drag Execute SQL TASK to your Control Flow. General: Result Set: Full result set Connection: Configure your connection SQLStatemen: SELECT ReportingDate, CreditCardNumber, DimLocationID FROM SourceUpdate WHERE (ReportingDate BETWEEN ? AND ?) Parameter Mapping: Create new variable.
Name DateEndSourceUpdate DateStartSourceUpdate Scope UpdateLocation UpdateLocation Data Type DateTime DateTime Value 6/30/2011 6/30/2011

Result Set: Create new variable.


Name ObjSourceUpdate Scope UpdateLocation Data Type Object Value System.Object

- Drag Foreach Loop Container to your Control Flow. Collection: Enumerator: Foreach ADO Enumerator ADO object source variable:
ObjSourceUpdate

Enumeration mode:
Rows in the first table

Variable Mappings: Create new variable.


Name Scope Data Type Value

NewLocationId OldLocationId

UpdateLocation UpdateLocation

int32 int32

0 0

-Drag a Data Flow Task 2. Your Data Flow: (the derive column and row count transformation is not crucial you can remove it if you want)

-Drag and drop your OLE DB Source Data Flow Create new variable for parameter mappings:
Name DateStartDestinationUpdate DateEndDestinationUpdate Scope UpdateLocation UpdateLocation Data Type DateTime DateTime Value 6/30/2011 6/30/2011

OLE DB Source Editor: OLEDB Connection Manager: Select your Connection SQL Command text: SELECT ReportingDate, Creditcardnumber, Dimlocationid FROM DestinationUpdate WHERE (ReportingDate BETWEEN ? AND ?) AND CreditCardNumber = ? ORDER BY ReportingDate

Parameter Mappings:

Derived Column Transformation Editor: Derived Column Name: DERLocationID Derived Column: <add as new column> Expression: Creditcardnumber == @[User::CreditCardNumber] && ReportingDate >= @[User::ReportingDate] && OldLocationid != @[User::NewLocationID] ? @[User::NewLocationID] : OldLocationid Data Type: four-byte signed integer [DT_I4] Conditional Split Transformation Editor:

Component Properties: Connection Managers: Configure your connection SQ Command: UPDATE FactFinancialDaily SET Dimlocationid = ? WHERE CreditCardNumber = ? AND ReportingDate = ? Column Mappings:

Row Count is just my counter ignore it.

Вам также может понравиться