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 2005 Forums
 Transact-SQL (2005)
 Copy data from text file to SQL table

Author  Topic 

besadmin
Posting Yak Master

116 Posts

Posted - 2009-07-23 : 16:05:31
Hey friends,

I need to copy data from a text file to a sql table. I know it must be possible becuase we are doing it in a DTS right now, but I need to move it to a stored procedure.

Here is what the text file looks like, this is the header row, and then the values correspond to it.
PurchaserName|CompanyName|StreetAddress|City|State|PostalCode|Postal4|Country|DatePurchased|ModelNumber|SerialNumber|DealerNumber|DealerZip|CrashNumber|PrimaryUseCode|DateProcessed|UserProcessed|PurchasedBefore|SugDigits|AreaCode|PhoneNumber


Any help is greatly appreciated as always!

Thanks a ton!

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-07-23 : 16:52:13
use BULK INSERT.

http://msdn.microsoft.com/en-us/library/ms188365.aspx
Go to Top of Page

besadmin
Posting Yak Master

116 Posts

Posted - 2009-07-23 : 16:54:41
Yup, cool. I think i got it!

I was having trouble becuase my last row did not have a \n at the end of it so it wasnt getting inserted.

I completed a working test though, pretty simple.

Thanks a ton for the reply!!

Later,

-S
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-07-23 : 17:01:17
Glad to help
Go to Top of Page
   

- Advertisement -