cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Insert CSV file from Sharepoint into SQL server table

Hi there,

 

Right now I'm building flow to get contents of my .csv file in my Sharepoint and insert it into my local SQL server table. I already can get the file from my Sharepoint but the next step seems blurry. I've searched through and can't find a way to process this.

 

I also tried this way but got stuck: https://powerusers.microsoft.com/t5/The-Power-Automate-Cookbook/read-csv-file-and-write-to-destinati...

 

Is there a simple to get this working? and by not using Parse CSV by Plumsail.

 

Thank you

5 REPLIES 5
Highlighted
Super User II
Super User II

Re: Insert CSV file from Sharepoint into SQL server table

Hi @aidelibrahim 

 

It's tricky that way. There's a simpler way by using the native CSV importer from SQL Server.

 

Try the following:

1. Import the file to SharePoint (you're doing this)

2. Add the file to a folder that you can reference

3. Use the following command:

 

BULK INSERT <Name of the table>
FROM '<path to file>\file.csv'
WITH
(
    FIRSTROW = 2,
    FIELDTERMINATOR = ',',  --CSV field delimiter
    ROWTERMINATOR = '\n',   --Use to shift the control to next row
    TABLOCK
)

 

If you're doing this just for yourself, you can just dump the file in a path and run the command. Easier than using Power Automation . But you can also use Power Automation to backup the file for example in SharePoint.

 

Does this makes sense?

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Cheers
Manuel

Highlighted
Frequent Visitor

Re: Insert CSV file from Sharepoint into SQL server table

Thank you @manuelstgomes ,

 

But can this method do automation process because I need to make sure this process is ongoing daily.

Highlighted
Super User II
Super User II

Re: Insert CSV file from Sharepoint into SQL server table

HI @aidelibrahim 

 

Sure. There are 2 steps to achieve that:

 

The file

Use Power Automation to dump the file in always the same location. You need the path to be the same for the next step. You can use the "Schedule" trigger to achieve this.

 

The bulk insert

You can use the code I provided you and put it inside a stored procedure. Then you just need to call it via Power Automation:

 

create proc dbo.BulkInsert
@filepath varchar(500)='<yourPathToTheFile>.csv'
as
begin
BULK INSERT <Name of the table>
FROM @filepath
WITH
(
    FIRSTROW = 2,
    FIELDTERMINATOR = ',',  --CSV field delimiter
    ROWTERMINATOR = '\n',   --Use to shift the control to next row
    TABLOCK
)

 

Does it make sense?

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Cheers
Manuel

Highlighted
Frequent Visitor

Re: Insert CSV file from Sharepoint into SQL server table

Thank you, but I'm not quite clear with the second step. Can you explain further?

Highlighted
Anonymous
Not applicable

Re: Insert CSV file from Sharepoint into SQL server table

Could you show the screenshots of the flow? I tried using instant flow(For selected file) to get the file in sharepoint but the flow could not be test.  

 

Annotation 2020-06-12 133313.png

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Upcoming Events

Experience what’s next for Power Automate

See the latest Power Automate innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Users online (3,156)