SQL Server Forums
Profile | Register | 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
 Transact-SQL (2008)
 Something similar to MySQL LOAD INFILE?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

KilpAr
Yak Posting Veteran

80 Posts

Posted - 05/24/2012 :  02:28:25  Show Profile  Reply with Quote
I would need to insert with VBA code a lot of rows into a table. I have a local tab-separated text file (C:\MyFile.txt) that I print from Excel and would need to upload the data in it into my SQL server table "MyTable". I tried with:

BULK Insert MyTable FROM 'C:\MyFile.txt' WITH(FIELDTERMINATOR = '\t',ROWTERMINATOR = '\n')

but it insists c:\MyFile.txt doesn't exist (I'm sure it does).

How am I supposed to refer to c:\MyFile.txt? With MySQL this worked easily using LOAD INFILE.

Edited by - KilpAr on 05/24/2012 02:28:42

khtan
In (Som, Ni, Yak)

Singapore
16746 Posts

Posted - 05/24/2012 :  02:50:34  Show Profile  Reply with Quote
The C:\MyFile.txt refers to the C: Drive on the Server where MS SQL Server is. Not your local drive.




KH
Time is always against us

Go to Top of Page

KilpAr
Yak Posting Veteran

80 Posts

Posted - 05/24/2012 :  03:03:20  Show Profile  Reply with Quote
quote:
Originally posted by khtan

The C:\MyFile.txt refers to the C: Drive on the Server where MS SQL Server is. Not your local drive.


Any way to make it refer to my local drive? Or is there any other options? I would prefer not to make hundreds of individual "INSERT INTO"-statements, but is that the only option?
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
16746 Posts

Posted - 05/24/2012 :  03:07:45  Show Profile  Reply with Quote
1. copy the file to the server

or

2. reference it using UNC Path \\computername\.....


KH
Time is always against us

Go to Top of Page

KilpAr
Yak Posting Veteran

80 Posts

Posted - 05/24/2012 :  03:40:41  Show Profile  Reply with Quote
Got it to work by copying it to the server and reading from there.

Thanks!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.09 seconds. Powered By: Snitz Forums 2000