Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 Inserting Multiple records at a time in sql table

Author  Topic 

Savi
Starting Member

1 Post

Posted - 2011-02-16 : 00:30:14
Hi Friends,
I am having a scenario of inserting data from flat file to sql server in SSIS

The requirements are

1.Flat file consisting of 100 records
2.program should do a batch insert of say 10 records at a time in a sql server table

I dont know how can we insert the records in a batch..Is there any solution for it..Please guide me





Savitha

YellowBug
Aged Yak Warrior

616 Posts

Posted - 2011-02-17 : 05:22:08
You can specify the batch size in the Advanced Editor for ADO NET Destination.
Look under the Custom Properties for BatchSize.
Go to Top of Page

joe_bolla
Starting Member

1 Post

Posted - 2011-12-05 : 06:45:34
What you can do is read the content from the flat file, format the data you want to insert into sql server into an XML format. the use SQL Server XML to insert it in one go as follows:
1. You declare and set an xml variable

declare @test nvarchar(max), @testxml xml

set @test = '<topic><dialog id="1" answerId="41">
<comment>comment 1</comment>
</dialog>
<dialog id="2" answerId="42" >
<comment>comment 2</comment>
</dialog>
<dialog id="3" answerId="43" >
<comment>comment 3</comment>
</dialog>
</topic>'

set @testxml = cast(@test as xml)

2. You run a simple XPath Query as follows:

insert @answerTemp
SELECT ParamValues.ID.value('@id','int') ,
ParamValues.ID.value('@answerId','int') ,
ParamValues.ID.value('(comment)[1]','VARCHAR(1000)')
FROM @testxml.nodes('topic/dialog') as ParamValues(ID)


View more details and code comments here: http://www.cyberminds.co.uk/blog/articles/how-to-insert-multiple-rows-in-sql-server.aspx

Thanks



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-05 : 06:54:51
quote:
Originally posted by Savi

Hi Friends,
I am having a scenario of inserting data from flat file to sql server in SSIS

The requirements are

1.Flat file consisting of 100 records
2.program should do a batch insert of say 10 records at a time in a sql server table

I dont know how can we insert the records in a batch..Is there any solution for it..Please guide me





Savitha


Why not dump the entire contents onto a staging table with an identity column and then use looping logic to fetch 10 records at a time from it?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -