Bulk Insert from a CSV file to a table in a remote server

Question:

I use SQL server 2012 and windows powershell. I try to do bulk insert from a local CSV file to a table in a remote server. I tried to combine bulk insert with powershell script by using sqlcmd to connect to that server to execute the sql statement. I come up with

obviously it does not work since path is my local path.

I then tried to put the file content to a variable but it still have error. It seems to say $var is not a table

I am a beginner in sql and powershell and does not have an idea how to do it.

Is there any body having any suggestions?

Thanks so much!

Answer:

If you have the SQL client tools installed on your local machine why not just use the bcp utility?

See this MSDN page for details of the bcp command.

Source:

Bulk Insert from a CSV file to a table in a remote server by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply