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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 Inserting Multiple records at a time in sql table
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Savi
Starting Member

India
1 Posts

Posted - 02/16/2011 :  00:30:14  Show Profile  Reply with Quote
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

United Kingdom
616 Posts

Posted - 02/17/2011 :  05:22:08  Show Profile  Reply with Quote
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 Posts

Posted - 12/05/2011 :  06:45:34  Show Profile  Reply with Quote
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

India
52326 Posts

Posted - 12/05/2011 :  06:54:51  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000