insert data from file to sql table

  • hi

    i have flat file like this

    TH*4.2*876545*P~~IO*3456*color~

    now i have two tables

    create table table1

    (id nvarchar(10),

    t1 int,

    t2 int primary key,

    t3 nvarchar(5),

    i1 int foreign key table2(i1))

    create table table2(

    id nvarchar(10),

    i1 int primary key,

    i2 nvarchar(10))

    now i need to insert this file record into table describe below.

    i cannot do it mannualy.

    if i use ssis package ,how can i1 value of table 1 will automatically insetered.

    any other way

    thanks

  • Insert it into a staging table first.

    Is there anything in the file that identifies the rows uniquely? Like a row number or anything like that?

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • no in the file there is no row number

    i need to know how to insert data into table which has primary -?foreign key relation.

    as you said staging table

    can you give me example.like i have given you two tables,can you explain me with that example

  • harri.reddy (10/24/2012)


    no in the file there is no row number

    i need to know how to insert data into table which has primary -?foreign key relation.

    as you said staging table

    can you give me example.like i have given you two tables,can you explain me with that example

    Can you give a bit more sample data and the desired output? It's not really clear what you want to do with the flat file rows.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • TH*4.2*876545*P~~IO*3456*color~ n

    my data would be like this

    table1

    id t1 t1 t3 i1

    TH 4.2 876545 p 3456

    table2

    id i1 i2

    iO 3456 color

    i need to do it using ssis

    here,i1 is primary key of table2 , which is foreign key of table1

    thanks

  • Use * as the delimiter for your flat file in the flat file connection manager.

    Duplicate the stream using the Multicast.

    Put two OLE DB destinations to your table, but write only the columns needed for the corresponding table.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • but how can i write primary -?foreign key in first table(i1)

  • You just write the same column (number 5 in your flat file) twice to the database.

    Once as a PK, once as a FK. So you need two OLE DB Destinations in your dataflow.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • u mean in header row delimiter i need to put *

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply