Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7808931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:16:42+00:00 2026-06-02T03:16:42+00:00

I have a scenario like below. Source Data like below (XML File):: ID CatType

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:16:44+00:00Added an answer on June 2, 2026 at 3:16 am

    Here is a sample SSIS package created using SSIS 2008 R2 that demonstrates what you are trying to achieve. The sample package loads the incoming file data into a staging table. Then using the SQL Server Rank function in conjunction with Partition clause you can load the data as per your requirement. This sample assumes that your database version SQL Server 2005 or above. Since you didn’t provide an exact XML file format, I have used CSV file format as the input files.

    • Let’s create two sample CSV files named Source_001.csv and Source_002.csv. Two files were created just to show the package logic works.

    Source_001

    Source_002

    • In the SQL Server database, create the destination table named dbo.CategoryName. This is the final table where data will be loaded into. It has the composite key on the columns Id and CatType.

    Destination table

    • In the SQL Server database, create the staging table named dbo.CategoryName_Staging. This is where the file data will be loaded into temporarily. This staging table structure mimics the incoming file structure.

    Staging table

    • In the SQL Server database, create a stored procedure named dbo.PopulateDestination using the script provided in the section Stored Procedure Script provided in the bottom of this post. This stored procedure uses RANK function in combination with PARTITION clause 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 named Source.

    Connection managers

    • Configure the flat file connection manager as shown below. I had placed the source csv file in the path C:\temp\

    Flat File General

    • On the Advanced tab of the Flat File Connection Manager Editor, rename the column information. LegacyId – integer, CatType – string (10), Name – string (30) the numbers denote the OutputColumnWidth.

    flat file columns

    • On the SSIS package’s control flow tab, place an Execute SQL task, followed by Data Flow Task and then followed by another Execute SQL task.

    SSIS control flow

    • Double-click on the first Execute SQL task and configure it to truncate the staging table.

    Truncate staging table

    • Double-click on the Data Flow Task to switch to the data flow tab. Inside the data flow tab, place a Flat File Source manager to read the CSV file and place an OLE DB Destination to write the data into the staging table.

    Data flow task

    • Configure the flat file source as shown below to read the flat file source using the flat file connection manager.

    Flat file connection manager

    Flat file columns

    • Configure the OLE DB destinaton as shown below to accept the incoming data and write into the destination file.

    OLE DB connection manager

    OLE DB columns

    • Go back to Control flow tab, configure the last Execute SQL task to invoke the newly created stored procedure. The package development is now complete.

    Execute SQL task to run stored procedure

    • Execute the package. Remember, the package is configured to read only the first source file Source_001.csv. After the package execution, query the destination table CategoryName to find the following data.

    Destination after first execution

    • Now, stop the SSIS package execution, double-click on the Flat File Connection Manager named Source. Change the file name path to Source_002.csv in order to read the second file.

    Change flat file connection file name

    • Execute the package again. The package is now configured to read the second source file Source_002.csv. This execution will append rows to the already populated desitnation table. After the package execution, query the destination table CategoryName to find the following addition data and note that the Id columns is correctly populater.

    Hope that helps.

    Destination table after second execution

    Stored Procedure Script:

    CREATE PROCEDURE [dbo].[PopulateDestination]
    AS
    BEGIN
        SET NOCOUNT ON;
    
        INSERT INTO dbo.CategoryName (Id, CatType, Name, LegacyId)
        SELECT      MAXID.Id + RANK() OVER(PARTITION BY CatType ORDER BY LegacyId) Id
                ,   CS.CatType
                ,   CS.Name
                ,   CS.LegacyId
        FROM        dbo.CategoryName_Staging    CS
        CROSS APPLY (
                        SELECT  COALESCE(MAX(Id), 0) Id
                        FROM    dbo.CategoryName C
                        WHERE   C.CatType = CS.CatType
                    ) MAXID
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a scenario like the one I described below... how can I accomplish
I have the following scenario(table below) where I would like to pick 'X' or
I have a chained XSLT 2.0 transformation scenario (using saxon), like this: - I1.xml
I have a scenario like this: form = MockRepository.GenerateMock<IAddAddressForm>(); mediator = new AddAddressMediator(form); The
I will like to know: I have a scenario. If a user adds a
I have a scenario outline table that looks like the following: Scenario Outline: Verify
I have this scenario where I would like to redirect my domains using the
I have an architecture scenario and I would like to discuss to get your
Consider the scenario I have values assigned like these Amazon -1 Walmart -2 Target
Here's the scenario: I'd like to have a host class that can have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.