cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
aidelibrahim
Level: Powered On

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

4 REPLIES 4
Super User
Super User

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

aidelibrahim
Level: Powered On

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
Super User

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

aidelibrahim
Level: Powered On

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?

Helpful resources

Announcements
firstImage

New Ranks and Rank Icons in April

Read the announcement for more information!

firstImage

Better Together Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (9,553)