Programatically Import Text File Into SQL Server 2005 - J. M. De Moor

12-Dec-07 04:30:29
BULK INSERT is pretty easy.  The tedious part is laying out the format
file.  We insert text to a #TempStaging table and populate the permanent
tables from there.

Joe
reply
 
 

Programatically Import Text File Into SQL Server 2005 - TheSQLGuru

12-Dec-07 06:09:51
In no particular order:

1) Import/Export wizard
2) OPENROWSET
3) bcp
4) BULK INSERT
5) INSERT with an EXEC xp_cmdshell ... type command.

--
Kevin G. Boles
TheSQLGuru
Indicium Resources, Inc.
reply
 

Programatically Import Text File Into SQL Server 2005 - Erland Sommarskog

12-Dec-07 06:16:20
(crjunk@earthlink.net) writes:

That or the command-line tool BCP. BULK INSERT is best if the
file lands on the SQL Server machine, or a network drive visible from
SQL Server, and you want to start the load from SQL Server.

If the file is a machine that is not accessible from SQL Server, BCP is
better.

The tools are functionally the same to a large extent. There are
some subtle differences, since they are different implementations, but
they are usually interchangeable.


BCP and BULK INSERT are nothing new to SQL 2005. SQL 2005 has
OPENROWSET(BULK which is new, and which use engine as BULK INSERT.
While it has some advantages, I tend to stick with BULK INSERT myself.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
reply
 

Programatically Import Text File Into SQL Server 2005 - crjun

15-Dec-07 04:51:47
I've got a text file that has fixed length fields/records delimited by
a pipe "|" that will need to be imported into my SQL Server 2005
database on a monthly basis.  What would be the best way to achieve
this?

I've been looking into using a BULK INSERT but I'm not sure if this is
the way to go.

I've worked with SQL Server 2000 off and on in the past, but SQL
Server 2005 is totaly new to me.


Thanks,

CR Junk
reply
 

Programatically Import Text File Into SQL Server 2005 - crjun

15-Dec-07 04:52:32
Thanks for everyone's suggestions.  I think I'm probably going to use
the BULK INSERT so I can call store my query as a stored procedure and
pass parameters to it.

One question:  If  I use a statement similar to the online help
example (shown below), then I should not need a format file. Am I
understanding this correctly?

BULK INSERT Northwind.dbo.[Order Details]
FROM 'f:\orders\lineitem.tbl'
WITH
(
FIELDTERMINATOR = '|',
ROWTERMINATOR = '|\n'
)


Thanks,
CR Junk
reply
 

Programatically Import Text File Into SQL Server 2005 - Erland Sommarskog

15-Dec-07 04:53:17
(crjunk@earthlink.net) writes:

Right. As long the file is regular enough and maps exactly to your
table you don't need a format file.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
reply
 

Programatically Import Text File Into SQL Server 2005 - crjun

15-Dec-07 04:54:03
Thanks!  After making a few changes to my tables and getting the user
accounts setup correctly, the BULK INSERT statements work great.

CR Junk
reply
 
promotion
Silverlight    WPF    WCF    WWF    LINQ   
JavaScript    AJAX    ASP.NET    XAML   
C#    VB.NET    VB 6.0    GDI+    IIS    XML   
.NET Generics    Anonymous Methods    Delegate   
Visual Studio .NET    Expression Blend    Virus   
Windows Vista    Windows XP    Windows Update   
Windows 2003 Server    Windows 2008 Server   
SQL Server    Microsoft Excel    Microsoft Word   
SharePoint    BizTalk    Virtual Earth   
.NET Compact Framework    Web Service   

"Everything" RSS / ATOM Feed Parser
How to send and receive messages through message queuing in .Net
How to Read text file as database
SQL Server 2005 Paging Performance Tip
Display code of web page.
Fully Scalable Excel File Importer class for .net using Microsoft Jet driver
Generic Chart Color Manager class that can be used for any charts
Helper class to style the infragistics wingrid
Using Reflection to detemine as Assembly Info in and out.
Helper class to play with Window (Owners and position)
Resolving displayname from the culture using the XmlLanguage and LanguageSpecificStringDictionary class