I have a scenario like below.
Source Data like below (XML File)::
ID CatType Name
11 A Raj
22 A Rai
33 B Raki
44 B Krish
55 A Rem
66 B Ram
I have to load above into below formate.
ID CatType Name LegacyID
1 A Raj 11
2 A Rai 22
1 B Raki 33
2 B Krish 44
3 A Rem 55
3 B Ram 66
ID and CatType are composite key in my destination table. I am getting CatType from source. While loading data, I have to increment ID by selecting Max(ID) where CatType= ?(based on CatType) in Destination table
How can I load these records in SSIS, could anyone point me in the right direction?
Here is a sample SSIS package created using
SSIS 2008 R2that demonstrates what you are trying to achieve. The sample package loads the incoming file data into a staging table. Then using the SQL ServerRankfunction in conjunction withPartitionclause you can load the data as per your requirement. This sample assumes that your database versionSQL Server 2005 or above. Since you didn’t provide an exact XML file format, I have used CSV file format as the input files.Source_001.csvandSource_002.csv. Two files were created just to show the package logic works.dbo.CategoryName. This is the final table where data will be loaded into. It has the composite key on the columnsIdandCatType.dbo.CategoryName_Staging. This is where the file data will be loaded into temporarily. This staging table structure mimics the incoming file structure.In the SQL Server database, create a stored procedure named
dbo.PopulateDestinationusing the script provided in the section Stored Procedure Script provided in the bottom of this post. This stored procedure usesRANKfunction in combination withPARTITIONclause to identify the correct Id that should be assigned to the CatType values.Create a new SSIS package. Create an OLE DB Connection manager named
SQLServer. This will point to your SQL Server database. Created a Flat File connection manager namedSource.C:\temp\LegacyId– integer,CatType– string (10),Name– string (30) the numbers denote the OutputColumnWidth.Execute SQL task, followed byData Flow Taskand then followed by anotherExecute SQL task.CategoryNameto find the following data.Source. Change the file name path toSource_002.csvin order to read the second file.CategoryNameto find the following addition data and note that the Id columns is correctly populater.Hope that helps.
Stored Procedure Script: