Connecting Tech Pros Worldwide Forums | Help | Site Map

import text file in sql 2005

Member
 
Join Date: Jul 2008
Posts: 43
#1: Dec 1 '08
i have a text file. I want to import it in table in sql 2005.that table has 8 fields.whn importing text file first 4 fields are in first line and next 2 in 2nd and rest 2 in last line. I want all 8 fields in one line. plz guide.

Newbie
 
Join Date: Dec 2008
Posts: 4
#2: Dec 1 '08

re: import text file in sql 2005


Since you are using SQL 2005, once way (where you would have more control over the import) is to use write a CLR stored procedure, that will read the file using a StreamReader that loops through the file and treats each 3 lines (and multiples thereof) as a single record and inserts into the table.
If you go this way, remember you can use Context Connection = True to refer to the database that you are calling to CLR SP from...

Hope this helps
-Shiva
mycodetrip.com
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#3: Dec 2 '08

re: import text file in sql 2005


What's the text file type? Delimited? Fixed?

-- CK
Reply