Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

insert data from file to sql table Expand / Collapse
Author
Message
Posted Wednesday, October 24, 2012 9:53 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, February 21, 2013 12:01 PM
Points: 149, Visits: 346
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
Post #1376562
Posted Wednesday, October 24, 2012 9:57 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 10:04 AM
Points: 15,442, Visits: 9,590
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
Post #1376566
Posted Wednesday, October 24, 2012 10:40 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, February 21, 2013 12:01 PM
Points: 149, Visits: 346
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
Post #1376586
Posted Thursday, October 25, 2012 12:24 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:26 AM
Points: 12,227, Visits: 9,198
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.




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1376796
Posted Thursday, October 25, 2012 6:59 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, February 21, 2013 12:01 PM
Points: 149, Visits: 346
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
Post #1376964
Posted Thursday, October 25, 2012 7:07 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:26 AM
Points: 12,227, Visits: 9,198
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.




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1376970
Posted Thursday, October 25, 2012 7:23 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, February 21, 2013 12:01 PM
Points: 149, Visits: 346
but how can i write primary -?foreign key in first table(i1)
Post #1376977
Posted Thursday, October 25, 2012 7:29 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:26 AM
Points: 12,227, Visits: 9,198
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.




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1376982
Posted Thursday, October 25, 2012 8:55 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, February 21, 2013 12:01 PM
Points: 149, Visits: 346
u mean in header row delimiter i need to put *
Post #1377054
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse