I found the solution. I’ve added a column assigned of the value of the execution of the SQL (SQLOperation([OP])[Status]{0}).
In this way the PostgreSQL.Database (or equivalent for other DB) is called and the DML (in this case an INSERT), is executed.
Regards,
Roberto
let
Source = Excel.Workbook(File.Contents("C:\Users\rstaltari\OneDrive - DXC Production\Desktop\Generated_Table_100000_Rows.xlsx"), null, true),
Generated_Table_100000_Rows_Sheet = Source{[Item="Generated_Table_100000_Rows",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Generated_Table_100000_Rows_Sheet, [PromoteAllScalars=true]),
#"Filtered Rows" = Table.SelectRows(#"Promoted Headers", each true),
// Corrected SQL query format
DML = Table.AddColumn(
#"Filtered Rows",
"OP",
each "BEGIN TRY INSERT INTO SalesRecords (RecordID, Name, Client, Amount) VALUES(" &
Text.From([RecordID]) & ", '" &
Text.From([Name]) & "', '" &
Text.From([Client]) & "', " &
Text.From([Amount]) &
") END TRY BEGIN CATCH END CATCH; SELECT 'Insert Successful' as Status;"
),
// Forcing the execution of SQL for each row
Execute = Table.AddColumn(
DML,
"SQLOperation",
each SQLOperation([OP])[Status]{0}, type text
)
in
Execute